async def cmd_civfrgivelvl20(self, *args, channel, guild: nextcord.Guild, **_): R = [ 652143977260122125, 682919453788471306, 682245125656805459, 708475004744106024, 708475862860824598, 751869750660956220, 708475012624941107, 708475021621723137, 708475860348567612, 708475861606596612, 708475862693052438, 708475864110596107 ] i = 0 members = guild.members for member in members: for role in member.roles: if role.id in R: db.set(member.id, "great_player", 1) await recalc_role_for(member) await channel.send( f"Le lvl 20 a été donnée à {member.mention} car il fait partie de l'équipe {role.mention}", allowed_mentions=nextcord.AllowedMentions(users=False, roles=False)) break i += 1 if i % 500 == 0: await channel.send(f"Progression: {i}/{len(members)}") await channel.send("DONE")
async def _black_formatting(self, message: nextcord.Message, content: str, member: nextcord.Member = None): if (not len(content.strip()) or content.find("```") < 0 or content.rfind("```") <= 0): code = content else: code = re.match(r"^.*?```(?:py|python)?\s*(.+?)\s*```\s*$", content, re.DOTALL).group(1) title = "✅ Formatting - Success" color = BLUE try: formatted_code = f"py\n{black.format_file_contents(code, mode=black.FileMode(), fast=True)}\n" except black.NothingChanged: title = "✅ Formatting - Nothing Changed" color = BLUE formatted_code = "Code already formatted correctly." except black.InvalidInput as e: title = "❌ Formatting - Invalid Input" color = YELLOW formatted_code = f"\n{e}\n" await message.channel.send( content="" if member is None else member.mention, embed=nextcord.Embed(title=title, description=f"```{formatted_code}```", color=color), reference=message, allowed_mentions=nextcord.AllowedMentions( replied_user=member is None, users=[member] if member else False), )
async def _exec_brainfuck(self, message: nextcord.Message, content: str): title = "✅ Exec Brainfuck - Success" color = BLUE code, user_input = re.match( r"^.*?```(?:bf|brainfuck)?\s*(.+?)\s*```\s*(.+)?$", content, re.DOTALL).groups() interpreter = BrainfuckInterpreter( code, user_input + "\n" if user_input else "") out, err = interpreter.run() output = [out] if err: title = "❌ Exec - Exception Raised" color = YELLOW output.append(err) elif not out: output = ["*No output or exceptions*"] out = "\n\n".join(output) if len(out) > 1000: out = out[:497] + "\n.\n.\n.\n" + out[-504:] await message.channel.send( embed=nextcord.Embed(title=title, description=f"```\n{out}\n```", color=color), reference=message, allowed_mentions=nextcord.AllowedMentions(replied_user=True), )
def __init__(self, case_insensitive=None, status=None): # defining allowed default mentions allowed_mentions = nextcord.AllowedMentions(everyone=False, roles=False) # defining intents usage intents = nextcord.Intents.default() intents.members = True intents.typing = False intents.webhooks = False intents.integrations = False # we now initialize the bot class super().__init__(command_prefix=get_prefix, case_insensitive=case_insensitive, status=status, allowed_mentions=allowed_mentions, intents=intents) self.database_online = True self.log = logging.getLogger("runner") self._cnx = [None, 0] self.database_keys = { 'user': '******', 'password': '******', 'host': '137.74.246.110', 'database': 'legends_club' } self.add_check(check_banned_use, call_once=True) self.fight_module = FightModule(self)
async def raw(self, ctx: nextcord.ext.commands.Context): message: nextcord.Message = ctx.message await ctx.send( f"```\n{message.content!r}\n```", allowed_mentions=nextcord.AllowedMentions(everyone=False, users=False, roles=False), )
async def on_message(self, message: nextcord.Message): if message.author.bot: return if self.server.me not in message.mentions: return if message.reference: return m: nextcord.Message = await message.channel.send( f"Hi {message.author.mention}! I'm the beginner.py bot developed collaboratively by members of this server " f"using the nextcord.py package! If you'd like to see my code or even contribute yourself I'm on GitHub " f"https://github.com/beginner-codes/beginner.py-bot", allowed_mentions=nextcord.AllowedMentions(users=[message.author]), ) await m.edit(suppress=True)
async def reveal(self, ctx): if not ctx.message.reference: await ctx.send("🛑 You must reply to a message.") return message = ctx.message.reference.resolved if not message or not message.content.strip(): await message.reply.send("*Empty Message*") return await message.reply( "> " + ("\n> ".join( message.content.replace("\\", "\\\\").replace( "<", r"\<").replace("> ", r"\> ").replace( "*", r"\*").replace("_", r"\_").replace( "`", r"\`").replace("|", r"\|").split("\n"))), allowed_mentions=nextcord.AllowedMentions(everyone=False, users=False, roles=False, replied_user=True), )
def send_messages(server, storage, now, send_message, dbg_srv): if "chan" not in storage: debug_msg(dbg_srv, send_message, "Channel not found") return chan = server.get_chan(storage["chan"]) if not chan: return (month, day) = (str(now.month), str(now.day)) if month not in storage["birthdays"]: debug_msg(dbg_srv, send_message, "Month not found") return if day not in storage["birthdays"][month]: debug_msg(dbg_srv, send_message, "Day not found") return for uid in storage["birthdays"][month][day]: user = server.get_user(uid) if not user: debug_msg(dbg_srv, send_message, f"User <@{user.id}> not found.") continue msg = storage["bday_message"].replace("<userid>", f"<@{user.id}>") try: send_message( msg, server=server, target=chan.id, check_old=False, allowed_mentions=nextcord.AllowedMentions(everyone=False, users=[user._raw], roles=False), ) except Exception as e: debug_msg(dbg_srv, send_message, f"Send Message Exception: {str(e)}") import traceback print(traceback.format_exc())
from a.funcs import f from a.stuff import conf import a.constants as tt async def get_prefix(bot, message): data = tt.config.find_one({'_id':message.guild.id},{'prefix':1}) if message.guild != None else None return commands.when_mentioned_or(config.prefix if not data else data.get('prefix', config.prefix))(bot, message) intents = nextcord.Intents.default() intents.members = True bot = commands.Bot( command_prefix = get_prefix, case_insensitive = True, intents = intents, allowed_mentions = nextcord.AllowedMentions(everyone=False,roles=False), ) ctx = commands.Context bot.remove_command('help') print(f"[{f._t()}] starting ...") for cog in tt.cogs: try: bot.load_extension('cogs.'+cog) tt.loaded.append(cog) print(f" \033[92m[+] loaded '{cog}'\033[0m") except Exception as error: print(f" \033[91m[x] failed to load '{cog}' \033[1m\n{''.join(traceback.format_exception(type(error), error, error.__traceback__))}\033[0m") if not tt.testing: for command in tt.misc.find_one({'_id':'misc'},{'disabled':1}).get('disabled', []): command = bot.get_command(command)
logger = logging.getLogger("nextcord") logger.setLevel(logging.DEBUG) handler = logging.FileHandler(filename="discord.log", encoding="utf-8", mode="w") handler.setFormatter( logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s") ) logger.addHandler(handler) # Enable intents god damn it discord intents = nextcord.Intents.default() intents.members = True # Reduce noise intents.typing = False allowed_mentions = nextcord.AllowedMentions(everyone=False, users=True, roles=True) client = nextcord.Client(intents=intents, allowed_mentions=allowed_mentions) bot = None bot_replies = {} to_delete = {} with open("plugin_data/twemoji_800x800.json") as f: emojis = json.load(f) raw_msg_cache = {} # message cache that we use to map msg_id to msg # TODO plp # slash commands # 1. Move all print statements to a logger # 2. Handle slash message timeouts
async def _exec( self, message: nextcord.Message, content: str, member: nextcord.Member = None, user_input: str = "", ): if (not len(content.strip()) or content.find("```") < 0 or content.rfind("```") <= 0): await message.channel.send( content="" if member is None else member.mention, embed=nextcord.Embed( title="Exec - No Code", description= ("\n**NO PYTHON CODE BLOCK FOUND**\n\nThe command format is as follows:\n\n" "\n!exec \\`\\`\\`py\nYOUR CODE HERE\n\\`\\`\\`\n"), color=RED, ), reference=message, allowed_mentions=nextcord.AllowedMentions( replied_user=member is None, users=[member] if member else False), ) return title = "✅ Exec - Success" color = BLUE restricted = not member.guild_permissions.manage_messages if not restricted: title += " (Super User 🦸)" if user_input: code, *_ = re.match(r"^.*?```(?:python|py)?\s*(.+?)\s*```.*$", content, re.DOTALL).groups() else: code, user_input = re.match( r"^.*?```(?:python|py)?\s*(.+?)\s*```\s*(.+)?$", content, re.DOTALL).groups() out, err, duration = await self.code_runner( "exec", code, user_input, restricted=restricted, ) output = [out] if err: title = "❌ Exec - Exception Raised" color = YELLOW output.append(err) elif not out: output = ["*No output or exceptions*"] out = "\n\n".join(output) old_out = out if out.count("\n") > 30: lines = out.split("\n") out = "\n".join(lines[:15] + [f".\n.\nRemoved {len(lines) - 30} lines\n.\n."] + lines[-17:]) if len(out) > 1000: out = ( old_out[:497] + f"\n.\n.\nRemoved {len(old_out) - 1000} characters\n.\n.\n" + old_out[-504:]) embed = nextcord.Embed( title=title, description=f"```\n{out}\n```", color=color ).set_footer( text=f"!exec modules | Completed in {duration:0.4f} milliseconds") if "https://xkcd.com/353/" in old_out: embed.set_image(url="https://imgs.xkcd.com/comics/python.png") await message.channel.send( content="" if member is None else member.mention, embed=embed, reference=message, allowed_mentions=nextcord.AllowedMentions( replied_user=member is None, users=[member] if member else False, roles=[], ), )
async def on_raw_reaction_add(self, reaction): if not self.settings.get("KUDOS_ENABLED", True): return if reaction.emoji.id not in self.reactions: return reacter: nextcord.Member = self.server.get_member(reaction.user_id) channel: nextcord.TextChannel = self.server.get_channel( reaction.channel_id) message: nextcord.Message = await channel.fetch_message( reaction.message_id) # Don't allow kudos in channels the user can't message in unless it's the archive if not channel.permissions_for(reacter).send_messages and ( not channel.category or channel.category.id != 829826306890924083): return if reacter.bot or message.author.bot: return if message.author.id == reaction.user_id: # Remove all kudos reactions a user tries to give them self await self.clear_previous_kudos(message, reaction.member, True) return level = self.reactions[reaction.emoji.id] kudos_left = self.points_left_to_give(reaction.user_id) kudos_points = self.point_values[level] if -1 < kudos_left < kudos_points: await channel.send( delete_after=5, embed=nextcord.Embed( color=RED, description= f"{reacter.mention} you don't have enough kudos right now", ), ) for r in message.reactions: if isinstance(r.emoji, str): continue kudos_level = self.reactions.get(r.emoji.id, False) if kudos_level == level: await r.remove(reacter) break return await self.clear_previous_kudos(message, reaction.member, level) kudos.remove_kudos(reaction.message_id, reaction.user_id) kudos.give_user_kudos(kudos_points, message.author.id, reaction.user_id, message.id) multiplier = self.get_pool_multiplier(reaction.member) kudos_message = ( f"{max(0, kudos_left - kudos_points)} of {self.pool_size * multiplier}" ) if multiplier == 0: kudos_message = "∞" await channel.send( embed=nextcord.Embed( color=BLUE, description= (f"{reacter.mention} gave {message.author.mention} {kudos_points} kudos!" ), ).set_footer( text= f"'!kudos help' or '!kudos leaderboard' | {kudos_message} kudos to give" ), reference=message, allowed_mentions=nextcord.AllowedMentions(replied_user=False), )