async def _list(self, ctx): """Lists the top Gods on the server.""" gods = database.getGods(ctx.guild.id) if not gods: await ctx.send("There are no Gods in " + ctx.guild.name + ", yet... `/gods create <name>`") return gods = list(gods) i = 1 godlist = "" for god in gods: if i > 15: break believers = database.getBelieversByID(god.ID) if not believers: believers = 0 else: believers = len(database.getBelieversByID(god.ID)) godtext = str("[" + str(i) + "] > #" + god.Name + "\n" " " + botutils.getGodString(god) + " of " + god.Type.capitalize() + "\n" " Power: " + str(round(god.Power, 2)) + "\n" " Believers: " + str(believers) + "\n") godlist = godlist + godtext i += 1 await ctx.send("**The Gods of " + ctx.guild.name + "**\n\n" "```pl\n" + godlist + "```")
async def _globallist(self, ctx): """Lists the top Gods globally""" gods = database.getGodsGlobal() if not gods: await ctx.send("There are no Gods, yet... `/gods create <name>`") return gods = list(gods) gods.reverse() i = 1 godlist = "" for god in gods: if i > 10: break believers = database.getBelieversByID(god.ID) if not believers: believers = 0 else: believers = len(database.getBelieversByID(god.ID)) guild_name = "NaN" guild = self.bot.get_guild(int(god.Guild)) if guild: guild_name = guild.name godtext = str("[" + str(i) + "] > #" + god.Name + "\n" " " + botutils.getGodString(god) + " of " + god.Type.capitalize() + "\n" " Power: " + str(round(god.Power, 2)) + "\n" " Believers: " + str(believers) + "\n" " Server: " + guild_name + "\n") godlist = godlist + godtext i += 1 await ctx.send("**The Global Gods Leaderboard**\n\n" "```pl\n" + godlist + "```")
def disbandGod(cls, godid): god = database.getGod(godid) if not god: return False believers = database.getBelieversByID(god.ID) if believers: for believer in believers: if not believer: return True believer.delete_instance() god.delete_instance() return True
async def _leave(self, ctx): """Leaves a religion""" user = ctx.author believer = database.getBeliever(ctx.author.id, ctx.guild.id) if not believer: return if database.leaveGod(user.id, ctx.guild.id): await ctx.send("You've left your god!") # If there aren't any believers in the God anymore, disband it if not database.getBelieversByID(believer.God): database.disbandGod(believer.God) elif believer.God.Priest == believer.ID: database.setPriest(believer.God.ID, None) # If the user was married, divorce them marriage = database.getMarriage(believer.ID) if marriage: database.deleteMarriage(marriage.ID) else: await ctx.send("Something went wrong...")
async def _info(self, ctx, *args): """Gets information about a God.""" if len(args) > 0: god = database.getGodName(args[0], ctx.guild.id) else: believer = database.getBeliever(ctx.author.id, ctx.guild.id) if believer: god = database.getGod(believer.God) else: await ctx.send("Please give a God name!") return if not god: await ctx.send("That God doesn't exist!") return embedcolor = discord.Color.green() if god.Type: if god.Type.upper() == "YAOI": embedcolor = discord.Color.from_rgb(204, 235, 245) if god.Type.upper() == "TRAPS": embedcolor = discord.Color.from_rgb(248, 184, 248) for godtype, color in botutils.godtypes: if godtype == god.Type: embedcolor = color title = god.Name + " - " + botutils.getGodString( god) + " of " + god.Type.capitalize() if god.Description: embed = discord.Embed(title=title, color=embedcolor, description=god.Description) else: embed = discord.Embed(title=title, color=embedcolor) embed.add_field(name="Creation Date", value="%s" % god.CreationDate.strftime("%Y-%m-%d %H:%M:%S"), inline=True) believers = database.getBelieversByID(god.ID) if not believers: believers = [] embed.add_field(name="Believers", value="%s" % len(believers), inline=True) embed.add_field(name="Power", value=round(god.Power, 1), inline=True) if god.Gender: embed.add_field(name="Gender:", value=god.Gender.capitalize(), inline=True) embed.add_field(name="Mood:", value=botutils.getGodMood(god.Mood), inline=True) embed.add_field(name="Invite Only:", value=god.InviteOnly, inline=True) if god.Priest: priest = self.bot.get_user( int(database.getBelieverByID(god.Priest).UserID)) embed.set_footer(text="Priest: %s" % priest.name + "#" + priest.discriminator, icon_url=priest.avatar_url) else: embed.set_footer(text="This God has no priest yet!", icon_url=self.bot.user.avatar_url) await ctx.send(embed=embed)
async def doNewPriestOffer(cls, bot, god, old_priestoffer=None): believers = database.getBelieversByID(god.ID) if len(believers) >= 2: logger.logDebug( "More than 3 believers in god, choosing new priest candidate!") iterations = 0 while True: if iterations > 3: logger.logDebug( "Did over 3 iterations trying to find priest offer... Breaking" ) break iterations += 1 believer = random.choice(believers) if old_priestoffer is not None: if believer.UserID == old_priestoffer.UserID: continue user = await botutils.getUser( bot, bot.get_guild(believer.God.Guild), believer.UserID) # Update the Database with the new priest offer database.newPriestOffer(god.ID, user.id) # Get DM channel dm_channel = user.dm_channel if dm_channel is None: await user.create_dm() dm_channel = user.dm_channel # Send the message to the user about being selected as new Priest guild = bot.get_guild(int(god.Guild)) try: await dm_channel.send( "Congratulations! You've been selected as the priest for **" + god.Name + "** on " "the " + guild.name + " server!\nWrite `/gods accept` to accept the request, or " "`/gods deny` to decline the request, on that server!") except Exception as e: # if we can't send the DM, the user probably has DM's off, at which point we would uhhh, yes await logger.log( "Couldn't send DM to user about being selected as a priest. User ID: " + str(user.id) + " - Error: " + str(e), bot, "INFO") # send a message to the user in a channel where the user can read, and the bot can send member = guild.get_member(user.id) bot_member = guild.get_member(bot.user.id) for channel in guild.channels: if isinstance(channel, discord.CategoryChannel) or isinstance( channel, discord.VoiceChannel): continue user_permissions = channel.permissions_for(member) bot_permissions = channel.permissions_for(bot_member) if user_permissions.send_messages & bot_permissions.send_messages: await channel.send( "<@" + str(user.id) + "> has been selected as the priest for **" + god.Name + "**!\nWrite `/gods accept` to accept the " "request, or `/gods deny` to decline the request!" ) break # Jump out of while loop break else: logger.logDebug( "Not more than 3 believers in god, skipping new priest candidate check" )