def make_response(self): if not self.get_step() and Config.validate_user_action( self.config, self.config['start_message'], self.user_response): #self.set_step(self.config['start_message']) next_message = Config.get_message_instance( messages=self.config['messages'], step=self.config['start_message']) else: step = self.get_step() message = Config.get_message_instance( messages=self.config['messages'], step=step) if self.user_response['type'] != 'message_new': return 'ok' print( self.user_response['type'], Config.validate_user_action(self.config, self.config['start_message'], self.user_response)) redirect = Config.check_keyword(message, self.user_response) if redirect is not None: next_message = Config.get_message_instance( messages=self.config['messages'], step=redirect) #self.set_step(step) else: next_message = Config.get_message_instance( messages=self.config['messages'], step=message['error_redirect']) _message_instance = Message(token=self.get_token(), user_id=self.user_id, template=next_message['message'], redis_connection=self.redis_connection) Config.get_handler_requirements(next_message, self.config) getattr(_message_instance, next_message['handler'])( **Config.get_handler_requirements(next_message, self.config)) self.set_step(next_message['key'])
async def on_raw_reaction_add(self, payload): config = Config() if payload.user_id == config.bot_id: return eroles = Data() if eroles.get_EmojiRole(payload.message_id) is None: return if payload.emoji.id is None: member, guild, emoji_id = self.parse_payload(payload) channel = guild.get_channel(payload.channel_id) message = await channel.fetch_message(payload.message_id) await message.remove_reaction(payload.emoji, guild.get_member(payload.user_id)) return erole = eroles.get_EmojiRole(payload.message_id) member, guild, emoji_id = self.parse_payload(payload) if erole.get_role_id(emoji_id) is None: channel = guild.get_channel(payload.channel_id) message = await channel.fetch_message(payload.message_id) await message.remove_reaction(payload.emoji, member) return role = find(lambda r: r.id == erole.get_role_id(emoji_id), guild.roles) member_role = find(lambda r: r == role, member.roles) if member_role is None: await member.add_roles(role) await member.send("You have been given **{}** role".format( role.name)) return await member.send("You already have **{}** role".format(role.name))
def edit_permission(self, perm, admin=None, roles=None, channels=None): config = Config() perm = config.get_permissions(perm) if admin != None: if admin.lower() == "true": admin = True elif admin.lower() == "false": admin = False else: admin = perm.admin perm.admin = admin if roles != None: perm.new_roles(roles) if channels != None: perm.new_channels(channels) config.edit_permission(perm)
def send_perm(self, name): perm = Config().get_permissions(name) roles = [] channels = [] for role in perm.roles: roles.append(next(iter(role)).replace("_role", "")) for channel in perm.channels: channels.append(next(iter(channel))) return PERM_STRING.format(name, perm.admin, roles, channels)
async def remove_reaction_message(self, ctx, message_id, emoji_input): try: message = await ctx.channel.fetch_message(message_id) except: pass emoji_id = self.parse_reaction_int(emoji_input) emoji = find(lambda e: e.id == emoji_id, ctx.guild.emojis) config = Config() await message.remove_reaction(emoji, ctx.guild.get_member(config.bot_id))
async def emoji_role_remove(self, ctx, message_id, emoji_input): message_id = int(message_id) try: message = await ctx.channel.fetch_message(message_id) emoji_id = self.parse_reaction_int(emoji_input) except: await ctx.message.delete() return emoji_id = self.parse_reaction_int(emoji_input) emoji = find(lambda e: e.id == emoji_id, ctx.guild.emojis) config = Config() await message.remove_reaction(emoji, ctx.guild.get_member(config.bot_id)) await ctx.author.send("Successfully removed {} from message".format( emoji.name)) await ctx.message.delete()
async def on_raw_reaction_remove(self, payload): config = Config() if payload.user_id == config.bot_id: return if payload.emoji.id is None: return eroles = Data() erole = eroles.get_EmojiRole(payload.message_id) if erole is None: return member, guild, emoji_id = self.parse_payload(payload) role = find(lambda r: r.id == erole.get_role_id(emoji_id), member.roles) if role is None: return await member.remove_roles(role) await member.send("**{}** role has been removed".format(role.name))
async def on_guild_role_update(self, before, after): if before.name != after.name: log.info("Updating config file: Guild Role Updated") Config().edit_role(before, after)
def __is_owner(ctx): return ctx.author.id == Config().bot_owner
async def on_guild_channel_update(self, before, after): if before.type == ChannelType.text and before.name != after.name: log.info("Updating config file: Guild Text_Channel Updated") Config().edit_channel(before, after)
async def config_manager_invite(self, ctx, link): config = Config() config.guild_invite = link config.update()
async def on_guild_channel_create(self, channel): if channel.type == ChannelType.text: log.info("Updating config file: Guild Text_Channel Created") Config().add_channel(channel)
async def on_guild_channel_delete(self, channel): if channel.type == ChannelType.text: log.info("Updating config file: Guild Text_Channel Deleted") Config().remove_channel(channel)
async def predicate(ctx): return Config().get_permissions(name).has_permission(ctx)
async def on_guild_role_delete(self, role): log.info("Updating config file: Guild Role Deleted") Config().remove_role(role)
async def on_guild_role_create(self, role): log.info("Updating config file: Guild Role Created") Config().add_role(role)
async def invite_link(self, ctx): await ctx.send(Config().guild_invite)
log = logging.getLogger("bot") log.setLevel(logging.DEBUG) filename = "bot/logs/wulfpack{}.log".format( datetime.now().strftime("%y-%m-%d-%M-%S")) handler = logging.FileHandler(filename=filename, encoding="utf-8", mode="w") handler.setFormatter( logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s')) log.addHandler(handler) handler = logging.StreamHandler() handler.setFormatter( logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s')) log.addHandler(handler) bot = commands.Bot(command_prefix="!", help_command=None, owner_id=174257170114805760) log.info("Loading cogs from config.yml...") try: for cog in Config().default_cogs: bot.load_extension(cog) except: log.error("Could not load cogs from config.yml") log.info("Loading cogs from list...") bot.load_extension("bot.cogs.manager") bot.load_extension("bot.cogs.startup") log.info("Running bot...") bot.run("TOKEN")