async def user_voice_connected(self, userid, channel): await self.print_admin_log( f'{User.get_at_mention(userid)} ({userid}) connected to :loud_sound:**{channel.name}**' ) if userid in self.members.keys(): member = self.members[userid] member.lock.acquire() member.last_login = datetime.datetime.now() member.active_since = datetime.datetime.now() member.last_active_xp = None if member.check_daily_reward() is True: await self.print_bot_message( Lang.get('DAILY_XP_REWARD_LOGIN', self.lang).replace( cfg.get_value('TEXTFILE_USER_MENTION'), User.get_at_mention(userid)).format( cfg.get_value('DAILY_REWARD_XP'))) member.lock.release() if self.members[userid].muted is True: await self.guild.get_member(userid).edit(mute=True) else: await self.guild.get_member(userid).edit(mute=False) if self.members[userid].deaf is True: await self.guild.get_member(userid).edit(deafen=True) else: await self.guild.get_member(userid).edit(deafen=False)
async def user_voice_moved(self, userid, before, after): user = self.members[userid] if after.id == self.afk_channel_id: user.lock.acquire() user.last_active_xp = None user.active_since = None user.lock.release() await self.print_admin_log( f'{User.get_at_mention(user.id)} ({ user.id }) moved from :sound:**{before.name}** and is now :zzz:**AFK**' ) if user.afk_mentions is True: await self.print_bot_message( Lang.get('USER_IS_AFK', self.lang).replace( cfg.get_value('TEXTFILE_USER_MENTION'), User.get_at_mention(user.id))) elif before.id == self.afk_channel_id: user.lock.acquire() user.last_active_xp = None user.active_since = datetime.datetime.now() user.lock.release() await self.print_admin_log( f'{User.get_at_mention(user.id)} ({user.id}) moved to :loud_sound:**{after.name}** and is no longer ~~**afk**~~' ) if user.afk_mentions is True: await self.print_bot_message( Lang.get('USER_NO_MORE_AFK', self.lang).replace( cfg.get_value('TEXTFILE_USER_MENTION'), User.get_at_mention(user.id))) else: await self.print_admin_log( f"{User.get_at_mention(user.id)} ({user.id}) moved from :sound:**{before.name}** to :loud_sound:**{after.name}**" )
async def send_dm_help(self, message): text = "" with open('./lang/en/dm_intro.txt') as fp: text += fp.read() with open('./lang/en/commands_help.txt') as fp: text += fp.read() await message.channel.send( text.replace(cfg.get_value('TEXTFILE_USER_MENTION'), User.get_at_mention(message.author.id)) .replace(cfg.get_value('TEXTFILE_BOT_MENTION'), User.get_at_mention(bot_id[0])) .replace(cfg.get_value('TEXTFILE_CMD_PREFIX_MENTION'), cfg.get_value('SRV_DEFAULT_CMD_PREFIX_NAME')))
def grant_connected_user_daily_reward(server, member): global bot_loop member.lock.acquire() if member.active_since is not None and member.check_daily_reward() is True: asyncio.run_coroutine_threadsafe( server.print_bot_message( Lang.get('DAILY_XP_REWARD_ACTIVE', server.lang).replace( cfg.get_value('TEXTFILE_USER_MENTION'), User.get_at_mention(member.id)).format( cfg.get_value('DAILY_REWARD_XP'))), bot_loop) member.lock.release()
def __init__(self, shard_id=None, shard_count=None): load_dotenv() self.servers = {} self.textfile_user_mention_tag = cfg.get_value('TEXTFILE_USER_MENTION') self.textfile_bot_mention_tag = cfg.get_value('TEXTFILE_BOT_MENTION') self.dm_help_cmd = cfg.get_value('SRV_DEFAULT_CMD_PREFIX_NAME') + 'help' self.dm_commands_cmd = cfg.get_value('SRV_DEFAULT_CMD_PREFIX_NAME') + 'commands' self.dm_invite_cmd = cfg.get_value('SRV_DEFAULT_CMD_PREFIX_NAME') + 'invite' super(DiscordClient, self).__init__(shard_id=shard_id, shard_count=shard_count) activity = self.dm_help_cmd + ' and ' + self.dm_invite_cmd self.activity = discord.Activity(name=activity, details=activity, state=activity, type=discord.ActivityType.listening)
def check_daily_reward(self): now = datetime.datetime.now() if self.last_daily_reward is None or ( now - self.last_daily_reward).total_seconds() >= 86400: self.last_daily_reward = now self.xp += cfg.get_value('DAILY_REWARD_XP') return True return False
def load(server): loaded_server = db.get_server(server.id) if loaded_server is None: print(f'no save found for {server.id}') return False if loaded_server['id'] != server.id: raise Exception( f"Can't load server {server.id} : IDs don't match !") server.lang = load_json_data(loaded_server, 'lang', cfg.get_value('SRV_DEFAULT_LANG')) server.bot_text_channel_name = load_json_data( loaded_server, 'bot_text_channel_name', cfg.get_value('SRV_DEFAULT_BOT_TEXT_CHANNEL_NAME')) server.log_text_channel_name = load_json_data( loaded_server, 'log_text_channel_name', cfg.get_value('SRV_DEFAULT_LOGS_TEXT_CHANNEL_NAME')) server.cmd_prefix = load_json_data( loaded_server, 'cmd_prefix', cfg.get_value('SRV_DEFAULT_CMD_PREFIX_NAME')) server.admin_logs = load_json_data( loaded_server, 'admin_logs', bool(cfg.get_value('SRV_DEFAULT_DISPLAY_ADMIN_LOGS'))) server.group_perks = load_json_data(loaded_server, 'group_perks', {}) server.use_accept_command = load_json_data( loaded_server, 'use_accept', bool(cfg.get_value('SRV_DEFAULT_USE_ACCEPT_COMMAND'))) server.use_accept_command = load_json_data( loaded_server, 'accept_rank', cfg.get_value('SRV_DEFAULT_ACCEPT_RANK')) for key, member in server.members.items(): for json_member in load_json_data(loaded_server, 'members', []): if load_json_data(json_member, 'id', -1) == member.id: User.from_json(json_member, member) break return True
async def cmd_stop_afk(server, userid, channel, message): # stop afk mentions (but keep admin logs) user = server.members[userid] user.afk_mentions = False await channel.send( Lang.get('CMD_STOPAFK', server.lang).replace(cfg.get_value('TEXTFILE_USER_MENTION'), User.get_at_mention(user.id))) return True
async def run_cmd(self, server, userid, channel, message): if not self.can_execute(server, userid): await channel.send(embed=simple_embed(value=Lang.get( 'MISSING_PERM', server.lang).replace( cfg.get_value('TEXTFILE_USER_MENTION'), User.get_at_mention(userid)), color=COLOR.RED)) return False else: return await self.action(server, userid, channel, message)
def grant_connected_user_xp(server, member, current_time): if member.active_since is not None: differ_time = member.last_active_xp if member.last_active_xp is None: differ_time = member.active_since diff_since_last_xp = math.floor( (current_time - differ_time).total_seconds() / 3600.0) if diff_since_last_xp >= 1: member.lock.acquire() member.xp = member.xp + (diff_since_last_xp * cfg.get_value('HOUR_ACTIVITY_REWARD_XP')) differ_time = differ_time + timedelta(hours=diff_since_last_xp) member.last_active_xp = differ_time member.lock.release()
def __init__(self, guild): self.lock = threading.Lock() self.guild = guild self.id = guild.id self.name = guild.name self.lang = cfg.get_value('SRV_DEFAULT_LANG') self.afk_channel_id = guild.afk_channel.id if guild.afk_channel is not None else -1 self.bot_text_channel_name = cfg.get_value( 'SRV_DEFAULT_BOT_TEXT_CHANNEL_NAME') self.log_text_channel_name = cfg.get_value( 'SRV_DEFAULT_LOGS_TEXT_CHANNEL_NAME') self.cmd_prefix = cfg.get_value('SRV_DEFAULT_CMD_PREFIX_NAME') self.admin_logs = bool(cfg.get_value('SRV_DEFAULT_DISPLAY_ADMIN_LOGS')) self.members = {} self.group_perks = {} self.accept_rank = cfg.get_value('SRV_DEFAULT_ACCEPT_RANK') self.use_accept_command = bool( cfg.get_value('SRV_DEFAULT_USE_ACCEPT_COMMAND')) self.welcome_message = cfg.get_value('SRV_DEFAULT_WELCOME_MESSAGE') self.goodbye_message = cfg.get_value('SRV_DEFAULT_GOODBYE_MESSAGE') for member in guild.members: self.members[member.id] = User(member)