async def autoelections(ctx): ctx.guild.settings[ "autoelections"] = not ctx.guild.settings["autoelections"] if ctx.guild.settings["autoelections"]: await ctx.send("Automatic elections on!") else: await ctx.send("Automatic elections off!") guilds_instance.save()
async def registerserver(ctx): if (guilds_instance.fetch_guild(ctx.message.guild.id) == None): presrole = await ctx.message.guild.create_role( name="President", color=discord.Color.gold(), hoist=True) guilds_instance.guilds.append( guilds.Guild(ctx.message.guild.id, electionChannel=ctx.message.channel.id, presidentRole=presrole.id)) await ctx.send("Guild registered!") guilds_instance.save()
async def runforoffice(ctx): #adds you to the list of presidential candidates if ctx.guild.phase == 0: inParty = False for party in ctx.guild.parties: if ctx.message.author.id in party.members: inParty = True if (not ctx.message.author.id in ctx.guild.candidates) and inParty: ctx.guild.candidates.append(message.author.id) await ctx.send('You are now a candidate!') guilds_instance.save() elif inParty == False: await ctx.send("Join a party first!") else: await ctx.send("You are already a candidate!") else: await ctx.send("Candidates are already locked in for this election!")
async def sell(ctx, price, quantity, *, item_name): quant = int(quantity) unitprice = float(price) if item_name.lower() in (item.lower() for item in ctx.player.inventory): g = server_registered(ctx.message.guild.id) if ctx.player.inventory[item_name][1] >= quant: ctx.player.deacquire(rpg_instance.finditem(item_name), quant) g.addlisting( guilds.Listing(rpg_instance.finditem(item_name), quant, unitprice, ctx.player)) await ctx.send("Listing posted.") guilds_instance.save() else: await ctx.send("You can't sell what you don't have!") elif unitprice < 0.00001 or unitprice > 99999999999: await ctx.send("Bad price") else: await ctx.send("You can't sell what you don't have!")
async def createparty(ctx, color, *, party_name): server = ctx.message.guild #leave old party oldparty = None for party in ctx.guild.parties: partyrole = server.get_role(party.role) if partyrole in ctx.message.author.roles: await ctx.message.author.remove_roles(partyrole) oldparty = party try: oldparty.members.remove(ctx.message.author.id) except: pass if oldparty: if oldparty.members == []: partyrole = server.get_role(oldparty.role) await partyrole.delete() ctx.guild.parties.remove(oldparty) #check if name exists party = None for p in ctx.guild.parties: if p.name == party_name: party = p if not party: #get color _color = get_color(color) if not _color: await ctx.send("Party could not be created") else: role = await ctx.message.guild.create_role(name=party_name, color=discord.Color( int(_color, 16)), hoist=True) await ctx.message.author.add_roles(role) colorrgb = webcolors.hex_to_rgb("#" + _color) ctx.guild.parties.append( guilds.Party(party_name, (colorrgb[0], colorrgb[1], colorrgb[2]), [ctx.message.author.id], role.id, "")) await ctx.message.channel.send('Party created successfully') else: await ctx.message.channel.send("That party already exists!") guilds_instance.save()
async def leaveparty(ctx): server = ctx.message.guild oldparty = None for party in ctx.guild.parties: partyrole = server.get_role(party.role) if partyrole in ctx.message.author.roles: await ctx.message.author.remove_roles(partyrole) oldparty = party try: oldparty.members.remove(ctx.message.author.id) except: pass if oldparty: if oldparty.members == []: partyrole = server.get_role(oldparty.role) await partyrole.delete() ctx.guild.parties.remove(oldparty) await ctx.send("Successfully left party") guilds_instance.save()
async def joinparty(ctx, *, party_name): server = ctx.message.guild name = ctx.message.content[11:] party = None for p in ctx.guild.parties: if p.name == name: party = p if party: party.members.append(ctx.message.author.id) #find old party oldparty = None for p in ctx.guild.parties: partyrole = server.get_role(p.role) if partyrole in ctx.message.author.roles: await ctx.message.author.remove_roles(partyrole) oldparty = p try: oldparty.members.remove(ctx.message.author.id) except: pass if oldparty and oldparty != party: if oldparty.members == []: partyrole = server.get_role(oldparty.role) await partyrole.delete() ctx.guild.parties.remove(oldparty) partyrole = server.get_role(party.role) try: await ctx.message.author.add_roles(partyrole) except: role = await server.create_role(name=party.name, color=discord.Color.from_rgb( party.color[0], party.color[1], party.color[2]), hoist=True) party.role = role.id await ctx.message.author.add_roles(role) await ctx.send('Joined!') else: await ctx.send('This party doesn\'t exist!') guilds_instance.save()
async def buy(ctx, number): g = guilds_instance.fetch_guild(ctx.message.guild.id) name = market_browsing[ctx.message.author.id] if name: listing = g.listings[name][int(number)] if listing.author == ctx.player or ctx.player.gold >= listing.totalprice: if ctx.player.acquire(listing.item, listing.quantity): await ctx.send( f"`{ctx.player.name} gained {listing.item.name}`\n") g.listings[name].remove(listing) if listing.author != ctx.player: #at this point, the transaction is successful, and between two different users salestax = (g.settings["salestax"] + 1) * listing.totalprice ctx.player.gold -= listing.totalprice + salestax g.bal += salestax listing.author.gold += listing.totalprice guilds_instance.save() else: await ctx.send("Your inventory isn't big enough!") else: await ctx.send("You don't have the money for that!")
async def resetelection(ctx): ctx.guild.phase = 0 guilds_instance.save()
async def forceelection(ctx): await ctx.guild.nextPhase(ctx.message.guild) guilds_instance.save()