def get_prefix(bot, message): v = database.select_many(dbobj.servers, id=message.guild.id) #print(v[0][1]) if v != [] and v != None: templist = [v[0][1]] templist.extend(when_mentioned(bot, message)) return templist else: return when_mentioned(bot, message)
async def prefix(_bot, message, only_guild_prefix=False): default = Settings.prefix if not message.guild: return commands.when_mentioned(_bot, message) + [default] config = await db.get_config(message.guild) if config: p = config.prefix else: p = default if only_guild_prefix: return p else: return commands.when_mentioned(_bot, message) + [p]
def get_prefix(bot, message): try: v = database.select_many(dbobj.servers, id=message.guild.id) except: return ["$"] #print(v[0][1]) test = False if v != [] and v != None and test == False: templist = [v[0][1]] templist.extend(when_mentioned(bot, message)) return templist else: return when_mentioned(bot, message)
def prefix(bot, message, only_guild_prefix=False): default = bot.properties.prefix if bot.properties else bot.default_prefix if not message.guild: return commands.when_mentioned(bot, message) + [default] if bot.config: config = bot.config.get_config(message.guild) p = config['prefix'] else: p = None p = p if p else default if only_guild_prefix: return p else: return commands.when_mentioned(bot, message) + [p]
async def get_guild_prefix(iceteabot, message: discord.Message): if message.guild is None: return commands.when_mentioned_or( *iceteabot.config['default_prefix'])(iceteabot, message) else: guild_data: models.Guild = iceteabot.get_guild_data( message.guild.id) if guild_data: if guild_data.prefixes: return commands.when_mentioned_or( *guild_data.prefixes.keys())(iceteabot, message) else: return commands.when_mentioned(iceteabot, message) else: return commands.when_mentioned(iceteabot, message)
def _get_prefix(bot, message, *, mentions=True): prefixes = commands.when_mentioned(bot, message) if mentions else [] if message.guild is None: prefixes.append(config.prefix) else: prefixes.extend(bot.prefixes.get(message.guild.id, [config.prefix])) return prefixes
def prefix(bot, message): r = [] r = commands.when_mentioned(bot, message) + r r.append( self.cached_prefix.get((message.guild or message.author).id, self.cmdprefix)) return r
async def get_prefix(bot_object, message): """This function is used by the bot to work with pings, and optionally a prefix.""" if bot_object.prefix is not None: return commands.when_mentioned_or(bot_object.prefix)( bot_object, message) # There is a prefix set. return commands.when_mentioned(bot_object, message) # There is no prefix set.
async def get_pre(self, message): ret = [commands.when_mentioned(self, message), "Akane ", "akane ", "(•ω•) "] if message.guild and message.guild.id == 169056767219597312: ret += ["ml ", "Ml ", "ML ", "mL "] if message.author.id == 132694825454665728: # Me ret += ["baka ", "bakane "] return ret
def get_prefix(self, bot, message): if message.guild.id not in self.prefixes: prefixes = self.default else: prefixes = self.prefixes[message.guild.id] return commands.when_mentioned(bot, message) + [prefixes]
async def on_message(self, message): if not message.guild: return if isinstance(message.author, discord.Member) and any( m in message.content for m in ['@everyone', '@here']): if self.bot.get_config(message.guild).get( 'mod.antieveryone') and not message.author.permissions_in( message.channel).mention_everyone: try: return await message.delete() except Exception: pass embeds = [str(e.to_dict()) for e in message.embeds] tokens = re.findall(self.tokenregex, str(message.system_content) + str(embeds), re.MULTILINE) config = self.bot.get_config(message.guild) if tokens and not self.bot.dev: try: await self.token_gist(tokens, message) except Exception as e: self.bot.logger.warn( f'Failed to upload token to gist (to reset ofc)', exc_info=e) if message.channel.id == 600070909365059584 and message.embeds: if 'new commit' in message.embeds[0].title and self.bot.dev: try: await message.publish() except Exception as e: self.bot.logger.warn(f'Failed to publish commit', exc_info=e) if message.channel.id == 388850472632451073: f = self.bot.get_channel(731330454422290463) if message.embeds[0].author.name in self.bot.config['datamine']: try: m = await f.send(embed=message.embeds[0]) await m.publish() except Exception: pass if not isinstance(message.author, discord.Member): return if message.author.bot: return if not await self.bot.has_ts_bot(message.guild): excluded = [ int(e) for e in config._data.get('excluded.filter', []) ] roleids = [r.id for r in message.author.roles] if message.author.id not in excluded and not any( r in excluded for r in roleids) and message.channel.id not in excluded: filters = self.bot.get_cog('Filters') # with suppress(Exception): await filters.run_all(message) if f'{message.content.strip()} ' in commands.when_mentioned( self.bot, message) and (await self.bot.blacklist_check(message)): prefix = self.bot.get_config(message.guild).get('main.prefix') await message.channel.send( f'Hey! My prefix here is `{prefix}` or you can mention me :)')
async def get_prefix(bot: commands.AutoShardedBot, message: discord.Message): """ Returns the prefix(es) for the bot """ prefixes = await sql.fetch("SELECT prefix FROM prefixes WHERE serverid=?", str(message.guild.id)) prefixes = [prefix[0] for prefix in [prefix[0] for prefix in prefixes]] return commands.when_mentioned_or(*prefixes)( bot, message) if prefixes else commands.when_mentioned(bot, message)
async def get_prefix(bot, message): for p in bot.prefixes: if bool(re.match(p, message.content, re.I)): return message.content[:len(p)] if message.guild: custom_prefix = await bot.funx.get_prefix(message.guild.id) if custom_prefix and re.match(custom_prefix, message.content, re.I): return message.content[:len(custom_prefix)] return commands.when_mentioned(bot, message)
async def get_main_prefix(self, message): """ Get the main prefix of wherever your message is from """ prefixes = await self.get_prefix(message) when_mentioned = commands.when_mentioned(self, message) if prefixes[0] == when_mentioned[0] and prefixes[1] == when_mentioned[ 1] and len(prefixes) > 2: prefixes = prefixes[2:] return prefixes if isinstance(prefixes, str) else prefixes[0]
def _get_prefix(bot: Bot, message: discord.Message, *, mentions: bool = True) -> List[str]: prefixes = commands.when_mentioned(bot, message) if mentions else [] if message.guild is None: prefixes.append(config.prefix) else: prefixes.extend(bot.prefixes.get(message.guild.id, [config.prefix])) return prefixes
async def on_message(self, message): if not message.guild: return embeds = [str(e.to_dict()) for e in message.embeds] tokens = re.findall(self.tokenregex, str(message.system_content) + str(embeds), re.MULTILINE) config = self.bot.get_config(message.guild) if tokens and not self.bot.dev: try: await self.token_gist(tokens, message) except Exception as e: self.bot.logger.warn( f'Failed to upload token to gist (to reset ofc)', exc_info=e) if message.channel.id == 600070909365059584 and message.embeds: if 'new commit' in message.embeds[0].title and self.bot.dev: try: await message.publish() except Exception as e: self.bot.logger.warn(f'Failed to publish commit', exc_info=e) if message.channel.id == 388850472632451073: f = self.bot.get_channel(731330454422290463) try: m = await f.send(embed=message.embeds[0]) await m.publish() except Exception: pass if not isinstance(message.author, discord.Member): return if message.author.bot: return if '--remind' in message.content and not self.bot.dev: content = re.sub(r'\s?--remind\s?', '', message.content, 0, re.MULTILINE) ctx = await self.bot.get_context(message) alt_ctx = await copy_context_with( ctx, content=ctx.config.get('main.prefix') + f'remind {content}') if alt_ctx.valid: await alt_ctx.command.invoke(alt_ctx) excluded = config.get('excluded.filter') roleids = [r.id for r in message.author.roles] if message.author.id not in excluded and not any( r in excluded for r in roleids) and message.channel.id not in excluded: filters = self.bot.get_cog('Filters') # with suppress(Exception): await filters.run_all(message) if f'{message.content.strip()} ' in commands.when_mentioned( self.bot, message): prefix = self.bot.get_config(message.guild).get('main.prefix') await message.channel.send( f'Hey! My prefix here is `{prefix}` or you can mention me :)')
async def get_prefixes(bot, message): prefix: Optional[str] = bot.config.prefix cache_key = f"{message.guild.id}:prefix" if bot.cache.exists(cache_key): prefix = bot.cache.get(cache_key).decode() if prefix: return when_mentioned_or(prefix)(bot, message) else: return when_mentioned(bot, message)
def get_prefix(self, bot, message: discord.Message): """ Dynamically get a server's prefix """ class CtxTmp: def __init__(self, message): self.message = message with db.database.session() as session: user = db.database.getUserFromCtx(session, CtxTmp(message))[0] if message.channel.type in [ discord.ChannelType.private, discord.ChannelType.group ]: # Get all the prefixes from each server the user is a part of prefixes = [s.prefix for s in user.servers] return prefixes + [commands.when_mentioned(bot, message)] server = user.active_server # Add the optional @ mention return [server.prefix, commands.when_mentioned(bot, message)]
async def _get_prefix(self, bot, message): if message.guild is None: prefix = ["?"] return commands.when_mentioned_or(*prefix)(bot, message) try: prefix = self.prefixes[message.guild.id] except KeyError: prefix = await self.load_prefixes(message.guild) if prefix is None: return commands.when_mentioned(bot, message) else: return commands.when_mentioned_or(*prefix)(bot, message)
async def command_prefix(bot, message): if message.guild is not None: prefix = await bot.pool.fetchval( """ SELECT prefix FROM meta.guilds WHERE id = $1; """, message.guild.id) else: prefix = None if prefix is not None: return commands.when_mentioned_or(prefix)(bot, message) else: return commands.when_mentioned(bot, message)
async def get_prefix_(self, bot, message): """ A coroutine that returns a prefix. I have made this a coroutine just to show that it can be done. If you needed async logic in here it can be done. A good example of async logic would be retrieving a prefix from a database. """ match = re.search(r'^!c4\s+', message.content) prefix = '' if match is None else match.group(0) if match: prefix = match.group(0) return commands.when_mentioned_or(prefix)(bot, message) else: return commands.when_mentioned(bot, message)
def get_prefixes(self, bot, message): prefixes = list(self.conf.global_) if message.guild is not None: prefixes += self.conf.guild_specific.get(message.guild.id, []) try: index = prefixes.index('mention') except ValueError: pass else: mentions = commands.when_mentioned(bot, message) prefixes[index] = mentions[0] prefixes.insert(index, mentions[1]) return prefixes
async def prefix(bot, msg): """Returns the prefix for the bot.""" if msg.guild is None: prefix_val = '!' elif msg.guild.id in bot.prefixes: return commands.when_mentioned_or(bot.prefixes[msg.guild.id])(bot, msg) else: async with bot.db.acquire() as conn: prefix_val = await conn.fetchval( """SELECT prefix FROM guilds WHERE guild_id = $1""", msg.guild.id) bot.prefixes[msg.guild.id] = prefix_val if not prefix_val: return commands.when_mentioned(bot, msg) return commands.when_mentioned_or(prefix_val)(bot, msg)
async def get_prefix(bot, message: discord.Message): """ get_prefix function. """ if not message.guild: prefixes = ['pb'] else: prefixes = bot.cache.prefixes.get(message.guild.id, ['pb']) for prefix in prefixes: match = re.match(f"^({prefix}\s*).*", message.content, flags=re.IGNORECASE) if match: return match.group(1) # fallback return commands.when_mentioned(bot, message)
def command_prefix(client: Bot, msg: Message) -> List[str]: """Callable to determine guild-specific prefix or default""" # Get default prefix and whether mentions count prefix_config = config.hgetall("prefix:config") prefix = [prefix_config["default_prefix"]] if prefix_config["when_mentioned"]: prefix.extend(when_mentioned(client, msg)) # If in a guild, check for guild-specific prefix if isinstance(msg.channel, TextChannel): guild_prefix = config.hget("prefix:guild", msg.channel.guild.id) if guild_prefix: prefix.append(guild_prefix) return prefix
async def get_prefix(bot, message: discord.Message): """ Get prefix function. """ if not message.guild: prefixes = ["pb"] else: prefixes = (await bot.cache.get_guild_info(message.guild.id))["prefixes"] if not prefixes: # couldn't find it or no prefixes prefixes = ["pb"] prefixes = sorted(prefixes, key=len) for prefix in prefixes: match = re.match(f"^({prefix}\s*).*", message.content, flags=re.IGNORECASE) if match: return match.group(1) # fallback return commands.when_mentioned(bot, message)
async def get_prefix(client, message): try: # Connect to the SQL DB. conn = sqlite3.connect('prefs.db') # Set type to string. conn.text_factory = str # Set the cursor for the connection. cur = conn.cursor() # Execute command on the db that looks for the prefix field where serverID match the incoming msg server ID. cur.execute( f'SELECT Prefix FROM servers WHERE ServerID={message.guild.id}') # Fetch the response. data = cur.fetchone() # Set a var named prefixer to the response from the query. prefixer = data # if the response is nothing if str(prefixer) == "None": # Explain what we're doing to the terminal. print("Prefix was none, executing SQL") # Format new empty values for the row, with the exception of the server ID. This is default for a server. # It will only run this once, because only once will it not find the prefix, because we set it here. prefs_query = f"""INSERT INTO servers (ServerID, Prefix, MutedRole, ModRoles, Welcome, WelcomeDM, WelcomeRole, WelcomeCard, WelcomeChannel) VALUES ('{message.guild.id}', '!', 'None', 'None', 'None', 'None', 'None', 0, 0) """ # Execute our query cur.execute(prefs_query) # Commit the changes. conn.commit() # Set prefixer to the default prefix. prefixer = "!" # Close the connection. conn.close() # Set Global Prefix to Prefixer prefix = prefixer # Return prefixer to our function entry point prefix = prefixer[0] prefixer = prefixer[0] prefixed = commands.when_mentioned(client, message) prefixed.append(prefixer) return prefixed except: prefixed = "!" return prefixed
async def command_prefix(bot, message): """Custom prefix function for guild-specific prefixes.""" default = config.prefix if message.guild is None: return default settings = await bot.get_guild_prefix(message.guild.id) if settings is None: return commands.when_mentioned_or(default)(bot, message) if settings['prefix'] is None: return commands.when_mentioned(bot, message) valid = [settings['prefix']] if settings['allow_default']: if isinstance(default, (tuple, list)): valid.extend(default) else: valid.append(default) valid.sort(reverse=True) return commands.when_mentioned_or(*valid)(bot, message)
async def determine_prefix(self, bot, message: discord.Message) -> list[str]: """ Procedure that determines the prefix for a guild. This determines the prefix when a global one is not being used "bot" is a required argument but also pointless since each AdamBot object isn't going to be trying to handle *other* AdamBot objects' prefixes """ watch_prefixes = [ await self.get_config_key(message, "prefix") if message.guild else None, self.global_prefix ] if watch_prefixes != [None] * len(watch_prefixes): return when_mentioned_or(*tuple( [prefix for prefix in watch_prefixes if type(prefix) is str]))( self, message ) # internal conf prefix or guild conf prefix can be used else: # Config tables aren't loaded yet or internal config doesn't specify another prefix, temporarily set to mentions only return when_mentioned(self, message)
async def get_prefix(self, bot: ClemBot, message: discord.Message): prefixes = [] # Check if bot is in BotOnly mode, if it is we cant get custom prefixes # so we have to fall back to self.default if not bot_secrets.secrets.bot_only: # noinspection PyBroadException try: # Try to grab the prefixes from the db, raise an error on failure # and bailout, we cant respond to anything at the moment prefixes = await bot.custom_prefix_route.get_custom_prefixes(message.guild.id, raise_on_error=True) except Exception as e: log.error('Custom prefix request failed with error: {error}', error=e) raise PrefixRequestError('Requesting custom prefix from the api failed') if len(prefixes) == 0: prefixes = [self.default] return commands.when_mentioned(bot, message) + prefixes
async def get_prefix(bot, message): sql = "SELECT `prefix` FROM `" + config['table']['guilds'] +"` WHERE `guildid` = " + str(message.guild.id) res = None checkDBCon(db) try: mycur.execute(sql) res = mycur.fetchall() except Exception as err: if isinstance(err, mysql.errors.OperationalError): db.reconnect(attempts=5, delay=5) if isinstance(err, mysql.errors.InterfaceError): print("Interface Error: Refused") else: print(err) db.reconnect(attempts=1, delay=0) if res is None: em = await message.channel.send("```css\nIt seems there is some [error]\nWait for some time or try Reinviting Me to the .Server!```") await em.delete(delay=7) return commands.when_mentioned(bot, message) pr = res[0]['prefix'] return commands.when_mentioned_or(pr)(bot, message)
def bare_pms(bot, message): if message.channel.is_private: return "" return when_mentioned(bot, message)