async def on_message(message): # disregard messages sent by our own bot if message.author.id == bot.user.id: return if Mysql.user_last_msg_check(message.author.id, message.content, helpers.is_private_dm( bot, message.channel)) == False: return await bot.process_commands(message)
async def on_message(message): # disregard messages sent by our own bot if message.author.id == bot.user.id: return # check if the owner is registered # must be done to add an entry to the db and initialize the db owner = config["owners"] for ids in owner: if Mysql.get_user(ids) is None: if message.author.id == ids: Mysql.register_user(ids) # check if the message is from a banned server if message.server is not None: if Mysql.check_for_server_status(message.server.id) == 2: return # check if staking account is set up staking_account = config["stake_bal"] if Mysql.get_staking_user(staking_account) is None: Mysql.register_user(staking_account) # check if treasury account is set up treasury_account = config["treasurer"] if Mysql.get_staking_user(treasury_account) is None: Mysql.register_user(treasury_account) # check if donation account is set up donate_account = config["donation"] if Mysql.get_staking_user(donate_account) is None: Mysql.register_user(donate_account) # check if game account is set up game_account = config["game_bal"] if Mysql.get_staking_user(game_account) is None: Mysql.register_user(game_account) # users that are not registered will be caught below # continue if the message is not from the bot if not message.author.bot: #config register keyword rkeyword = str(config["register_keyword"]) prefix = str(config["prefix"]) #rkeywordcall is the register command for users not registered rkeywordcall = prefix + rkeyword coin_name = str(config["currency_symbol"]) #authid is the unique discord id number for the user that send the message to the server authid = message.author.id #check if the message author is in the database (meaning they are registered) if Mysql.get_user(authid) is None: #if they they are not it the database but send the if str(message.content).startswith(rkeywordcall) is True: Mysql.register_user(authid) await bot.send_message( message.channel, '{} You are Now Registered. :tada:'.format( message.author.mention)) await bot.send_message( message.author, 'Thank You for registering. Use {}deposit to check your {} deposit address' .format(prefix, coin_name)) return elif str(message.content).startswith(prefix) is True: await bot.send_message( message.channel, '{} You are NOT registered. Type **{}** to begin.'.format( message.author.mention, rkeywordcall)) return else: if Mysql.user_last_msg_check( message.author.id, message.content, helpers.is_private_dm(bot, message.channel)) == False: return await bot.process_commands(message)
async def rain(self, ctx, amount: float): """Rain all active users""" config = parsing.parse_json('config.json') CURRENCY_SYMBOL = config["currency_symbol"] rain_config = parsing.parse_json('config.json')['rain'] RAIN_MINIMUM = rain_config['min_amount'] RAIN_REQUIRED_USER_ACTIVITY_M = rain_config['user_activity_required_m'] USE_MAX_RECIPIENTS = rain_config['use_max_recipients'] MAX_RECIPIENTS = rain_config['max_recipients'] if ctx.message.guild is not None: await ctx.message.delete() message = ctx.message if helpers.is_private_dm(self.bot, message.channel): return if amount < RAIN_MINIMUM: await ctx.send( "**:warning: Amount {:.8f} {} for rain is less than minimum {} required! :warning:**" .format(float(amount), CURRENCY_SYMBOL, float(RAIN_MINIMUM))) return snowflake = str(ctx.message.author.id) mysql.check_for_user(snowflake) balance = mysql.get_balance(snowflake, check_update=True) if float(balance) < amount: await ctx.send( "{} **:warning:You cannot rain more {} than you have!:warning:**" .format(ctx.message.author.mention, CURRENCY_SYMBOL)) return # Create tip list active_id_users = mysql.get_active_users_id( RAIN_REQUIRED_USER_ACTIVITY_M, True) # Remove yourself from the list of active users to rain on if int(ctx.message.author.id) in active_id_users: active_id_users.remove(int(ctx.message.author.id)) # users_list is all members on the server that have registered with the bot users_list = [] for user in ctx.message.guild.members: if mysql.check_for_user(user.id) is not None: users_list.append(user) # List all registered members server_users = [x for x in users_list] # Remove yourself from the list of active users to rain on if ctx.message.author in server_users: server_users.remove(ctx.message.author) server_users = [x for x in server_users if x.bot == False] active_users = [] for user in server_users: if int(user.id) in active_id_users: active_users.append(user) if USE_MAX_RECIPIENTS: len_receivers = min(len(active_users), MAX_RECIPIENTS) else: len_receivers = len(active_users) if len_receivers == 0: await ctx.send( "{}, you are all alone if you don't include bots! Trying raining when people are online and active." .format(ctx.message.author.mention)) return amount_split = math.floor(float(amount) * 1e8 / len_receivers) / 1e8 if amount_split == 0: await ctx.send( "{} **:warning:{:.8f} {} is not enough to split between {} users:warning:**" .format(ctx.message.author.mention, float(amount), CURRENCY_SYMBOL, len_receivers)) return receivers = [] for active_user in active_users: receivers.append(active_user.mention) mysql.check_for_user(active_user.id) mysql.add_tip(snowflake, active_user.id, amount_split) if len(receivers) == 0: await ctx.send( "{}, you are all alone if you don't include bots! Trying raining when people are online and active." .format(ctx.message.author.mention)) return await ctx.send( ":cloud_rain: {} **Rained {:.8f} {} on {} users** (Total {:.8f} {}) :cloud_rain:" .format(ctx.message.author.mention, float(amount_split), CURRENCY_SYMBOL, len_receivers, float(amount), CURRENCY_SYMBOL)) users_soaked_msg = [] idx = 0 for users in receivers: users_soaked_msg.append(users) idx += 1 if (len(users_soaked_msg) >= 25) or (idx == int(len_receivers)): await ctx.send("{}".format(' '.join(users_soaked_msg))) del users_soaked_msg[:] users_soaked_msg = []
async def rain(self, ctx, amount: float): """Rain all active users""" config = parsing.parse_json('config.json') CURRENCY_SYMBOL = config["currency_symbol"] rain_config = parsing.parse_json('config.json')['rain'] RAIN_MINIMUM = rain_config['min_amount'] RAIN_REQUIRED_USER_ACTIVITY_M = rain_config['user_activity_required_m'] USE_MAX_RECIPIENTS = rain_config['use_max_recipients'] MAX_RECIPIENTS = rain_config['max_recipients'] message = ctx.message if helpers.is_private_dm(self.bot, message.channel): return if amount < RAIN_MINIMUM: await self.bot.say( "**:warning: Amount {} for rain is less than minimum {} required! :warning:**" .format(amount, RAIN_MINIMUM)) return snowflake = ctx.message.author.id mysql.check_for_user(snowflake) balance = mysql.get_balance(snowflake, check_update=True) if float(balance) < amount: await self.bot.say( "{} **:warning:You cannot rain more money than you have!:warning:**" .format(ctx.message.author.mention)) return # Create tip list active_id_users = mysql.get_active_users_id( RAIN_REQUIRED_USER_ACTIVITY_M, True) if int(ctx.message.author.id) in active_id_users: active_id_users.remove(int(ctx.message.author.id)) if USE_MAX_RECIPIENTS: len_receivers = min(len(active_id_users), MAX_RECIPIENTS) else: len_receivers = len(active_id_users) if len_receivers == 0: await self.bot.say( "{}, you are all alone if you don't include bots! Trying raining when people are online and active." .format(ctx.message.author.mention)) return amount_split = math.floor(float(amount) * 1e8 / len_receivers) / 1e8 if amount_split == 0: await self.bot.say( "{} **:warning:{} is not enough to split between {} users:warning:**" .format(ctx.message.author.mention, amount, len_receivers)) return active_users = [ x for x in ctx.message.server.members if int(x.id) in active_id_users and x.bot == False ] receivers = [] for active_user in active_users: receivers.append(active_user.mention) mysql.check_for_user(active_user.id) mysql.add_tip(snowflake, active_user.id, amount_split) if len(receivers) == 0: await self.bot.say( "{}, you are all alone if you don't include bots! Trying raining when people are online and active." .format(ctx.message.author.mention)) return long_soak_msg = "{} **Rained {} {} on {} [{}] :moneybag:**".format( ctx.message.author.mention, str(amount_split), CURRENCY_SYMBOL, ', '.join([x for x in receivers]), str(amount)) if len(long_soak_msg) > 2000: await self.bot.say( "{} **Rained {} {} on {} users [{}] :moneybag:**".format( ctx.message.author.mention, str(amount_split), CURRENCY_SYMBOL, len_receivers, str(amount))) else: await self.bot.say(long_soak_msg)
async def on_message(message): if message.guild: if message.guild.id != config["discord"]["server"]: return if message.channel.id != config["discord"]["channel"]: return print('') print(message) print(message.content) messageslog.info('{}{} {} {} {} {} | {}'.format( str(message.guild.id) + ' ' if message.guild else '', str(message.guild) if message.guild else 'DM', str(message.channel.id), str(message.channel), str(message.author.id), str(message.author), str(message.content))) # disregard messages sent by our own bot if message.author.id == bot.user.id: return # check if the owner is registered # must be done to add an entry to the db and initialize the db owner = config["owners"] for ids in owner: if Mysql.get_user(ids) is None: if message.author.id == ids: Mysql.register_user(ids) # users that are not registered will be caught below # continue if the message is not from the bot if not message.author.bot: # print('author no bot') # config register keyword rkeyword = str(config["register_keyword"]) prefix = str(config["prefix"]) # rkeywordcall is the register command for users not registered rkeywordcall = prefix + rkeyword coin_name = str(config["currency_symbol"]) # authid is the unique discord id number for the user that send the message to the server authid = message.author.id # check if the message author is in the database (meaning they are registered) if Mysql.get_user(authid) is None: if str(message.content).startswith(rkeywordcall) is True: Mysql.register_user(authid) await message.channel.send('{} Welcome! :tada:'.format( message.author.mention)) await message.channel.send( 'Thank You for registering. Use {}deposit to check your {} deposit address' .format(prefix, coin_name)) return elif str(message.content).startswith(prefix) is True: Mysql.register_user(authid) await message.channel.send( 'Welcome! {0} You are Now Registered. :tada:.\nUse:\n{1}bal to check your {2} balance\n{1}deposit to get your {2} deposit address' .format(message.author.mention, prefix, coin_name)) return else: if Mysql.user_last_msg_check( message.author.id, message.content, helpers.is_private_dm(bot, message.channel)) is False: return if str(message.content).startswith(prefix) is True: botlog.info('{}{} {} {} {} {} | {}'.format( str(message.guild.id) + ' ' if message.guild else '', str(message.guild) if message.guild else 'DM', str(message.channel.id), str(message.channel), str(message.author.id), str(message.author), str(message.content))) await bot.process_commands(message)
async def rain(self, ctx, amount: float, usercount=None): """Rain all active users. optional: select random [usercount] from active users""" if usercount: try: usercount = int(usercount) if usercount < 1: return except ValueError as e: print('ValueError:', e) pass print('usercount:', usercount) config = parsing.parse_json('config.json') CURRENCY_SYMBOL = config["currency_symbol"] rain_config = parsing.parse_json('config.json')['rain'] RAIN_MINIMUM = rain_config['min_amount'] RAIN_REQUIRED_USER_ACTIVITY_M = rain_config['user_activity_required_m'] USE_MAX_RECIPIENTS = rain_config['use_max_recipients'] MAX_RECIPIENTS = rain_config['max_recipients'] if helpers.is_private_dm(self.bot, ctx.message.channel): return if amount < 0: await ctx.send( "**:warning: Nice try! :smile: ..but the amount can not be negative. :warning:**" .format(float(amount), CURRENCY_SYMBOL, float(RAIN_MINIMUM))) return if amount < RAIN_MINIMUM: await ctx.send( "**:warning: Amount {:.8f} {} for rain is less than minimum {:.8f} required! :warning:**" .format(float(amount), CURRENCY_SYMBOL, float(RAIN_MINIMUM))) return snowflake = ctx.message.author.id balance = mysql.get_user_balance(snowflake, check_update=True) if not balance: return if float(balance) < amount: await ctx.send( "{0} **:warning: You cannot rain more {1} than you have! :warning:**\n..your {1} balance: {2:.8f}" .format(ctx.message.author.mention, CURRENCY_SYMBOL, float(balance))) return # Create tip list active_id_users = mysql.get_active_users_id( RAIN_REQUIRED_USER_ACTIVITY_M, True) if int(ctx.message.author.id) in active_id_users: active_id_users.remove(int(ctx.message.author.id)) users_list = [] for user in ctx.message.guild.members: if user.id in active_id_users: users_list.append(user) if len(users_list) == 0: await ctx.send( "{}, you are all alone if we don't include bots! Trying raining when people are online and active." .format(ctx.message.author.mention)) return print(users_list) if USE_MAX_RECIPIENTS: if len(users_list) > MAX_RECIPIENTS: users_list = list( random.sample(set(users_list), k=MAX_RECIPIENTS)) if usercount: if len(users_list) > usercount: users_list = list(random.sample(set(users_list), k=usercount)) amount_split = math.floor(float(amount) * 1e8 / len(users_list)) / 1e8 print('amount_split:', amount_split) if amount_split == 0: await ctx.send( "{} **:warning:{:.8f} {} is not enough to split between {} users:warning:**" .format(ctx.message.author.mention, float(amount), CURRENCY_SYMBOL, len(users_list))) return receivers = [] for active_user in users_list: print(active_user) print(active_user.mention) receivers.append(active_user.mention) self.rainlog.info('{:40s} {} {:17.8f} {}'.format( str(active_user), active_user.id, float(amount_split), CURRENCY_SYMBOL)) mysql.add_rain(snowflake, active_user.id, amount_split) if len(receivers) == 0: await ctx.send( "{}, you are all alone if we don't include bots! Trying raining when people are online and active." .format(ctx.message.author.mention)) return self.rainlog.info('{:40s} {} {:17.8f} {}'.format( str(ctx.message.author), ctx.message.author.id, -float(amount), CURRENCY_SYMBOL)) totalrain = round(amount_split * float(len(receivers)), 8) print('totalrain:', totalrain) await ctx.send( ":cloud_rain: {} **Rained {:.8f} {} on {} users** (Total {:.8f} {}) :cloud_rain:" .format(ctx.message.author.mention, float(amount_split), CURRENCY_SYMBOL, len(receivers), totalrain, CURRENCY_SYMBOL)) users_soaked_msg = [] idx = 0 for x in receivers: users_soaked_msg.append(x) idx += 1 if (len(users_soaked_msg) >= 50) or (idx == len(receivers)): await ctx.send("{}".format(' '.join(users_soaked_msg))) del users_soaked_msg[:] users_soaked_msg = []