예제 #1
0
 async def reactionHandler(self, payload):
     server = client.guilds[0]
     member = discord.utils.get(server.members, id=int(payload.user_id))
     memberRoles = []
     for role in member.roles:
         memberRoles.append(role.name)
     if config["reactionlimits"]["db"]:
         bannedRoles = db.getList("reactBan")
         bypassRoles = db.getList("reactPass")
         polls = db.getPolls()
     else:
         requestedItems = ["bannedroles", "bypassroles", "polls"]
         output = {}
         for item in requestedItems:
             if item in config["reactionlimits"].keys():
                 output[item] = config["reactionlimits"][item]
             else:
                 output[item] = []
         bannedRoles = output["bannedroles"]
         bypassRoles = output["bypassroles"]
         polls = output["polls"]
         if polls == []:
             polls = {}
     targetpoll = {}
     if any(elem in bannedRoles for elem in memberRoles) and not any(elem in bypassRoles for elem in memberRoles):
         targetpoll["reactionchannel"] = str(payload.channel_id)
         targetpoll["messageid"] = str(payload.message_id)
         targetpoll["limit"] = 0
     elif polls != {}:
         for poll in polls:
             poll = polls[poll]
             if str(payload.message_id) == poll["messageid"] and str(payload.channel_id) == poll["reactionchannel"]:
                 targetpoll = poll
     if targetpoll == {}:
         return
     if config["reactionlimits"]["db"]:
         # Redis is so bad that it can't even store integers for some reason
         targetpoll["limit"] = int(targetpoll["limit"])
     for channel in server.channels:
         if str(channel.id) == targetpoll["reactionchannel"]:
             reactionMessage = await channel.fetch_message(targetpoll["messageid"])
             break
     if payload.message_id == reactionMessage.id:
         i = 0
         userIDList = []
         for reaction in reactionMessage.reactions:
             users = await reaction.users().flatten()
             for user in users:
                 userIDList.append(user.id)
         for userID in userIDList:
             if payload.user_id == userID:
                 i += 1
         req = False
         if "bypassroles" not in targetpoll.keys():
             targetpoll["bypassroles"] = []
         if "bannedroles" in targetpoll.keys():
             req = (all(elem in targetpoll["bannedroles"] for elem in memberRoles) and not all(elem in targetpoll["bypassroles"] for elem in memberRoles))
         if i > targetpoll["limit"] or req:
             for reaction in reactionMessage.reactions:
                 await reaction.remove(member)
예제 #2
0
 def checkout(self):
     self.parent.destroy()
     table = db.getList()
     total = 0.0
     for item in table:
         total += float(item.cost)
         #print("{0:.2f}".format(total)) #debugging
     checkout = tk.Tk()
     checkout.title("Checkout")
     checkout.geometry("205x300")
     checkoutWindow(checkout, total)
예제 #3
0
    def initComponents(self):
        #init all 'list' window components here
        #contents frame
        contentsFrame = ttk.Frame(self)
        contentsFrame.grid(column=0, row=0, columnspan=2, sticky='')

        #item list
        ttk.Label(contentsFrame, text="List:").grid(column=0,
                                                    row=0,
                                                    pady=10,
                                                    sticky=tk.N)
        self.displayList(db.getList(), contentsFrame)
예제 #4
0
 async def dbRoleAssign(self, member=None, message=None):
     if message is not None:
         member = message.author
     user = db.getDict(str(member.id))
     isMember = "roles" in user.keys()
     isEveryone = "everyone" in db.redisKeys()
     if isMember or isEveryone:
         givenroles = []
         if isMember:
             roles = db.stringListToList(user["roles"])
             for role in roles:
                 givenroles.append(role)
         if isEveryone:
             everyone = db.getList("everyone")
             for role in everyone:
                 givenroles.append(role)
         rolelist = await self.clean_list(givenroles)
         roles = []
         for role in givenroles:
             role = discord.utils.get(member.guild.roles, name=role)
             if role is None:
                 if message is not None:
                     em = discord.Embed(title="ERROR", description="\nFailed to assign the following roles: " + rolelist + ".")
                     msg = await message.channel.send(embed=em)
                     sleep(2)
                     await msg.delete()
                     message = None
                 break
             roles.append(role)
         for role in roles:
             await member.add_roles(role)
         if message is not None:
             em = discord.Embed(title="SUCCESS", description="\nAssigned the following roles: " + rolelist + ".")
             msg = await message.channel.send(embed=em)
             sleep(2)
             await msg.delete()
     else:
         if message is not None:
             em = discord.Embed(title="ERROR", description="\nFailed to assign roles, if you think this is an error, please contact " + "<@" + config["admintoken"] + "> to fix this.")
             msg = await message.channel.send(embed=em)
             sleep(2)
             await msg.delete()
예제 #5
0
    def __init__(self, parent, total):
        ttk.Frame.__init__(self, parent, padding="10 10 10 10")
        self.parent = parent

        self.total = tk.StringVar()
        total = "{0:.2f}".format(total)
        self.total.set(total)

        contentsFrame = ttk.Frame(parent)
        contentsFrame.grid(column=0, row=0, columnspan=2, sticky=tk.E)
        listFrame = ttk.Frame(parent)
        listFrame.grid(column=0, row=1, columnspan=2, pady=10, sticky='')

        ttk.Label(listFrame, text="Your items were:").grid(column=0,
                                                           row=0,
                                                           pady=10,
                                                           sticky='')

        self.displayList(db.getList(), listFrame)

        ttk.Label(contentsFrame,
                  text="The total of your cart is:").grid(column=0,
                                                          row=0,
                                                          pady=10,
                                                          sticky='')
        ttk.Label(contentsFrame, text=self.total.get()).grid(column=0,
                                                             row=1,
                                                             pady=10,
                                                             sticky='')
        ttk.Label(contentsFrame,
                  text="Would you like to checkout?").grid(column=0,
                                                           row=2,
                                                           pady=10,
                                                           sticky='')

        ttk.Button(parent, text="Yes", command=self.yes).grid(row=2, column=0)
        ttk.Button(parent, text="No",
                   command=self.restartCart).grid(row=2, column=1, sticky=tk.E)