async def cmd_set_lang(server, userid, channel, message): splited_message = str(message.content).split() new_lang = splited_message[1].lower() server.lang = new_lang await channel.send(Lang.get('CMD_LANG_SET', server.lang).format(new_lang)) return True async def cmd_get_lang(server, userid, channel, message): await channel.send( Lang.get('CMD_LANG_GET', server.lang).format(server.lang)) return True async def cmd_lang(server, userid, channel, message): splited_message = str(message.content).split() if len(splited_message) == 1: # No argument, display current server lang return await LangGetCmd.run_cmd(server, userid, channel, message) else: # Argument found, changing the lang return await LangSetCmd.run_cmd(server, userid, channel, message) LangGetCmd = ServerCmd('langget', cmd_get_lang) LangGetCmd.required_perks = ['cmd.lang', 'cmd.lang.display'] LangSetCmd = ServerCmd('langset', cmd_set_lang) LangSetCmd.required_perks = ['cmd.lang', 'cmd.lang.change'] LangCmd = ServerCmd('lang', cmd_lang) LangCmd.required_perks = ['cmd.lang', 'cmd.lang.display', 'cmd.lang.change']
return True async def cmd_xp(server, userid, channel, message): split_message = message.content.split() if len(split_message) > 1 and len(split_message) - len( message.mentions) == 2: return await XpGiveCmd.run_cmd(server, userid, channel, message) elif len(split_message) > 1 and len(message.mentions) > 0: return await XpDisplayOtherCmd.run_cmd(server, userid, channel, message) else: return await XpDisplaySelfCmd.run_cmd(server, userid, channel, message) XpDisplaySelfCmd = ServerCmd('xpself', cmd_user_xp_get_self) XpDisplaySelfCmd.required_perks = ['cmd.xp', 'cmd.xp.display', 'cmd.xp.self'] XpDisplayOtherCmd = ServerCmd('xpother', cmd_user_xp_get_other) XpDisplayOtherCmd.required_perks = [ 'cmd.xp', 'cmd.xp.display', 'cmd.xp.display.other' ] XpGiveCmd = ServerCmd('xpgive', cmd_user_xp_give) XpGiveCmd.required_perks = ['cmd.xp', 'cmd.xp.give'] XpCmd = ServerCmd('xp', cmd_xp) XpCmd.required_perks = [ 'cmd.xp', 'cmd.xp.give', 'cmd.xp.display', 'cmd.xp.display.other', 'cmd.xp.display.self' ]
import discord from lang.lang import Lang from cmds.cmd import ServerCmd from user import User async def cmd_unmute(server, userid, channel, message): split_content = str(message.content).split() if len(message.mentions) < 1: await channel.send(Lang.get('CMD_WRONG_SYNTAX', server.lang)) await channel.send(f"`{server.cmd_prefix}unmute <users>`") return False for mention in message.mentions: if mention.id not in server.members.keys(): raise Exception(f'Cannot find user ({ mention.id }) in server') pass server.members[mention.id].lock.acquire() server.members[mention.id].muted = False server.members[mention.id].muted_until = None if mention.voice is not None: await mention.edit(mute=False) await channel.send( f"{User.get_at_mention(mention.id)} has been unmuted by {User.get_at_mention(userid)}" ) server.members[mention.id].lock.release() return True UnmuteCmd = ServerCmd('unmute', cmd_unmute) UnmuteCmd.required_perks = ['cmd.unmute']
if len(split_content) > len(message.mentions) + 1: time = int(split_content[-1]) for mention in message.mentions: if mention.id not in server.members.keys(): raise Exception(f'Cannot find user ({ mention.id }) in server') pass server.members[mention.id].lock.acquire() server.members[mention.id].muted = True if mention.voice is not None: await mention.edit(mute=True) if time > 0: server.members[mention.id].muted_until = datetime.now( ) + timedelta(seconds=time) await channel.send( Lang.get('CMD_MUTE_TIME', server.lang).format(User.get_at_mention(mention.id), User.get_at_mention(userid), time)) else: server.members[mention.id].muted_until = None await channel.send( Lang.get('CMD_MUTE', server.lang).format(User.get_at_mention(mention.id), User.get_at_mention(userid))) server.members[mention.id].lock.release() return True MuteCmd = ServerCmd('mute', cmd_mute) MuteCmd.required_perks = ['cmd.mute']
accept = ':green_circle: ' + Lang.get('YES', server.lang) refuse = ':red_circle: ' + Lang.get('NO', server.lang) await channel.send( Lang.get('CMD_ACCEPT_TOGGLE', server.lang).format( accept if server.use_accept_command else refuse, server.cmd_prefix)) return True async def cmd_accept_group_set(server, userid, channel, message): if len(message.role_mentions) < 1: await channel.send( f"{Lang.get('CMD_WRONG_SYNTAX', server.lang)}\r\n`{server.cmd_prefix}acceptgroup <group>`" ) return False server.accept_rank = message.role_mentions[0].name await channel.send( Lang.get('CMD_ACCEPT_GROUP_SET', server.lang).format(message.role_mentions[0].mention, server.cmd_prefix)) return True ToggleAcceptCmd = ServerCmd('toggleaccept', cmd_toggle_accept) ToggleAcceptCmd.required_perks = ['cmd.accept.toggle'] AcceptGroupCmd = ServerCmd('acceptgroup', cmd_accept_group_set) AcceptGroupCmd.required_perks = ['cmd.accept.set'] AcceptCmd = ServerCmd('accept', cmd_accept)
new_prefix = splited_message[1] server.cmd_prefix = new_prefix await channel.send(f"Le prefix est maintenant `{new_prefix}`.") return True async def cmd_get_prefix(server, userid, channel, message): await channel.send(f"Le prefix actuel est `{server.cmd_prefix}`.") return True async def cmd_prefix(server, userid, channel, message): splited_message = str(message.content).split() if len(splited_message ) == 1: # No argument, display current command prefix return await PrefixGetCmd.run_cmd(server, userid, channel, message) else: # Argument found, changing the prefix return await PrefixSetCmd.run_cmd(server, userid, channel, message) PrefixGetCmd = ServerCmd('prefixget', cmd_get_prefix) PrefixGetCmd.required_perks = ['cmd.prefix', 'cmd.prefix.display'] PrefixSetCmd = ServerCmd('prefixset', cmd_set_prefix) PrefixSetCmd.required_perks = ['cmd.prefix', 'cmd.prefix.change'] PrefixCmd = ServerCmd('prefix', cmd_prefix) PrefixCmd.required_perks = [ 'cmd.prefix', 'cmd.prefix.display', 'cmd.prefix.change' ]
from cmds.cmd import ServerCmd from user import User from datetime import datetime, timedelta from math import floor from lang.lang import Lang async def cmd_daily_reward(server, userid, channel, message): if userid in server.members.keys(): member = server.members[userid] now = datetime.now() daily_time = 86400 - (now - member.last_daily_reward).total_seconds() seconds = floor(daily_time % 60) minutes = floor(daily_time / 60) hours = floor(minutes / 60) minutes = minutes % 60 display = f"{str(hours) + Lang.get('HOURS', server.lang) + ' ' if hours > 0 else ''}{str(minutes) + Lang.get('MINUTES', server.lang) + ' ' if minutes > 0 else ''}{str(seconds) + Lang.get('SECONDS', server.lang) + ' ' if seconds > 0 else ''}" await channel.send( Lang.get('NEXT_DAILY_XP_REWARD', server.lang).format(User.get_at_mention(userid), display)) return True return False DailyRewardCmd = ServerCmd('daily', cmd_daily_reward) DailyRewardCmd.required_perks = ['cmd.daily_reward'] DailyRewardAliasCmd = ServerCmd('dailyreward', cmd_daily_reward) DailyRewardAliasCmd.required_perks = ['cmd.daily_reward']
# cmd_xp.py import discord from user import User from lang.lang import Lang from cmds.cmd import ServerCmd from utils import COLOR, simple_embed import psycopg2 async def cmd_force_save(server, userid, channel, message): saving_embed = simple_embed(value='Saving server state..', color=COLOR.ORANGE) saved_embed = simple_embed(value='Server saved !', color=COLOR.LIGHT_GREEN) save_error_embed = simple_embed(value='Server save failed !', color=COLOR.RED) msg = await channel.send(embed=saving_embed) try: server.save(server) except psycopg2.OperationalError: await msg.edit(embed=save_error_embed) return False except psycopg2.Error: await msg.edit(embed=save_error_embed) return False await msg.edit(embed=saved_embed) return True ForceSaveCmd = ServerCmd('forcesave', cmd_force_save) ForceSaveCmd.required_perks = ['cmd.forcesave']
) await server.members[userid].display_warnings(channel) return True async def cmd_player_other_warns_display(server, userid, channel, message): for mention in message.mentions: if mention.id not in server.members.keys(): raise Exception( f'Cannot display user warns ({mention.id}) : user id not found in this guild' ) await server.members[mention.id].display_warnings(channel) return True async def cmd_player_warns_display(server, userid, channel, message): if len(message.mentions) < 1: # self displays warnings return await WarnsSelfCmd.run_cmd(server, userid, channel, message) else: return await WarnsOtherCmd.run_cmd(server, userid, channel, message) WarnsSelfCmd = ServerCmd('warnsself', cmd_player_self_warns_display) WarnsSelfCmd.required_perks = ['cmd.warns', 'cmd.warns.self'] WarnsOtherCmd = ServerCmd('warnsother', cmd_player_other_warns_display) WarnsOtherCmd.required_perks = ['cmd.warns', 'cmd.warns.other'] WarnsCmd = ServerCmd('warns', cmd_player_warns_display) WarnsCmd.required_perks = ['cmd.warns', 'cmd.warns.self', 'cmd.warns.other']
# cmd_stop_afk.py from lang.lang import Lang from config import cfg from cmds.cmd import ServerCmd from user import User 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 StopAfkCmd = ServerCmd('stopafk', cmd_stop_afk) StopAfkCmd.required_perks = ['cmd.stopafk']
server.group_perks[str(role.id)] = add_perks await channel.send(Lang.get('CMD_PERM_UPDATE', server.lang).format(' '.join([r.mention for r in message.role_mentions]))) return True async def cmd_get_perms(server, userid, channel, message): for role in message.role_mentions: if str(role.id) in server.group_perks.keys(): perks = server.group_perks[str(role.id)] if len(perks) == 0: await channel.send(f"{role.mention} ne possède aucune permission.") else: await channel.send(f"Permission(s) du rôle {role.mention} : {', '.join(perks)}") else: await channel.send(f"{role.mention} ne possède aucune permission.") return True async def cmd_perm(server, userid, channel, message): if len(message.role_mentions) < 1: await channel.send(f"{Lang.get('CMD_WRONG_SYNTAX', server.lang)}\r\n`{server.cmd_prefix}perm <roles> <permissions>`") return False else: if len(str(message.content).split()[len(message.role_mentions) + 1:]) < 1: return await cmd_get_perms(server, userid, channel, message) else: return await cmd_set_perm(server, userid, channel, message) PermCmd = ServerCmd('perm', cmd_perm) PermCmd.required_perks = ['cmd.perm', 'cmd.perm.display', 'cmd.perm.change']
# cmd_version import discord from config import cfg from cmds.cmd import ServerCmd from user import User from utils import bot_id, simple_embed, COLOR async def cmd_version(server, userid, channel, message): text = '{} is running under version `{}`'.format( User.get_at_mention(bot_id[0]), cfg.BOT_VERSION) embed = simple_embed(value=text, color=COLOR.LIGHT_BLUE) await message.channel.send(embed=embed) return True VersionCmd = ServerCmd('version', cmd_version) VersionCmd.required_perks = ['cmd.version']
# cmd_afk.py from lang.lang import Lang from config import cfg from cmds.cmd import ServerCmd from user import User async def cmd_afk(server, userid, channel, message): # stop afk mentions (but keep admin logs) user = server.members[userid] user.afk_mentions = True await channel.send(Lang.get('CMD_AFK', server.lang).replace(cfg.get_value('TEXTFILE_USER_MENTION'), User.get_at_mention(user.id))) return True AfkCmd = ServerCmd('afk', cmd_afk) AfkCmd.required_perks = ['cmd.afk']
# cmd_dice.py from cmds.cmd import ServerCmd from utils import simple_embed, COLOR import random async def cmd_dice(server, userid, channel, message): split_message = message.content.split() num_dice = 1 if len(split_message) > 1: try: num_dice = int(split_message[1]) if num_dice < 1: num_dice = 1 elif num_dice > 9: num_dice = 9 except ValueError: num_dice = 1 dice_embed = simple_embed(color=COLOR.LIGHT_PURPLE) dice_embed.clear_fields() for i in range(num_dice): dice_embed.add_field(name=':game_die:', value='\32' + str(random.randint(1, 6)), inline=True) await channel.send(embed=dice_embed) DiceCmd = ServerCmd('dice', cmd_dice) DiceCmd.required_perks = ['cmd.dice']
import discord from lang.lang import Lang from cmds.cmd import ServerCmd from user import User async def cmd_undeafen(server, userid, channel, message): split_content = str(message.content).split() if len(message.mentions) < 1: await channel.send(Lang.get('CMD_WRONG_SYNTAX', server.lang)) await channel.send(f"`{server.cmd_prefix}undeafen <users>`") return False for mention in message.mentions: if mention.id not in server.members.keys(): raise Exception(f'Cannot find user ({ mention.id }) in server') pass server.members[mention.id].lock.acquire() server.members[mention.id].deaf = False server.members[mention.id].deaf_until = None if mention.voice is not None: await mention.edit(deafen=False) await channel.send( f"{User.get_at_mention(mention.id)} has been undeafen by {User.get_at_mention(userid)}" ) server.members[mention.id].lock.release() return True UndeafenCmd = ServerCmd('undeafen', cmd_undeafen) UndeafenCmd.required_perks = ['cmd.undeafen']
split_content = message.content.split() if len(split_content) < 2: await channel.send("Missing League of Legends username") return False msg = await channel.send(f":arrows_counterclockwise: *Loading TFT games for {split_content[1]}..*") load_tft_user(split_content[1]) if len(loaded_tft_user.games) < 1: await msg.delete() await channel.send(f"No TFT game found for {loaded_tft_user.name}") else: games_count = len(loaded_tft_user.games) for i in range(0, min(5, games_count)): game = loaded_tft_user.games[i] if game.loaded is False: game.load() games_msg = f"Last 5 TFT games for {loaded_tft_user.name}" for i in range(0, min(5, games_count)): game = loaded_tft_user.games[i] participant = game.get_participant(loaded_tft_user.puuid) games_msg += "\r\n" games_msg += f"{i+1} - *[{game.game_time.strftime('%Y-%m-%d %H:%M:%S')}]* **{participant.placement}/8 {':trophy:' if participant.placement == 1 else ''}**" await msg.delete() await channel.send(games_msg) return True TFTCmd = ServerCmd('tft', cmd_tft) TFTCmd.required_perks = ['cmd.tft']
time = -1 if len(split_content) > len(message.mentions) + 1: time = int(split_content[-1]) for mention in message.mentions: if mention.id not in server.members.keys(): raise Exception(f'Cannot find user ({ mention.id }) in server') server.members[mention.id].lock.acquire() server.members[mention.id].deaf = True if mention.voice is not None: await mention.edit(deafen=True) if time > 0: server.members[mention.id].deaf_until = datetime.now() + timedelta( seconds=time) await channel.send( Lang.get('CMD_DEAFEN_TIME', server.lang).format(User.get_at_mention(mention.id), User.get_at_mention(userid), time)) else: server.members[mention.id].deaf_until = None await channel.send( Lang.get('CMD_DEAFEN', server.lang).format(User.get_at_mention(mention.id), User.get_at_mention(userid))) server.members[mention.id].lock.release() return True DeafenCmd = ServerCmd('deafen', cmd_deafen) DeafenCmd.required_perks = ['cmd.deafen']