Пример #1
0
 async def _run(self):
     state = engine.STATE.get(self.message.channel.id)
     if state and state.command == self:
         await state.message.delete()
         database.set_inv(self.message.guild.id, self.message.author.id, state.candy_value, update=True)
         await self.send(state.pick_str)
         del engine.STATE[self.message.channel.id]
Пример #2
0
 async def _run(self):
     user = self.args["user"]
     amount = self.args["amount"]
     candy = self.args["candy"]
     candy_value = CandyValue(candy, amount)
     database.set_inv(self.server.id, user.id, candy_value)
     await discord.send_embed(
         self.message.channel,
         f"You now have {candy_value.small_str} (set by {self.message.author.mention})",
         author=user)
Пример #3
0
 async def _run(self):
     item = self.args["item"]
     inv = database.get_inv(self.server.id, self.author.id)[self.author.id]
     if inv >= item.cost:
         role = discord.get_role(self.message.guild, item.item)
         user = self.message.author
         if role in user.roles:
             await self.send("You already have that role!")
         else:
             database.set_inv(self.server.id,
                              self.author.id,
                              -item.cost,
                              update=True)
             await discord.apply_role(self.message.author, role)
             database.set_stats_shop(self.server.id)
             await self.send(f"You have bought the {role.mention} role!")
     else:
         await self.send(f"You need {item.cost.line_str} to buy this item!")
Пример #4
0
 async def _run(self):
     invs = database.get_inv(self.message.guild.id, self.message.author.id,
                             self.user.id)
     if invs[self.message.author.id][self.candy] < self.amount:
         await discord.send_embed(self.message.channel,
                                  f"You don't have enough {self.candy}!",
                                  author=self.message.author)
     else:
         candy_value = CandyValue(self.candy, self.amount)
         database.set_inv(self.message.guild.id,
                          self.message.author.id,
                          -candy_value,
                          update=True)
         database.set_inv(self.message.guild.id,
                          self.user.id,
                          candy_value,
                          update=True)
         await discord.send_embed(
             self.message.channel,
             f"You have been gifted {candy_value.small_str} by {self.message.author.mention}\n"
             f"You now have {(invs[self.user.id][self.candy] + candy_value).small_str}",
             author=self.user)
Пример #5
0
    async def _run(self):
        user = self.args["user"]
        amount = self.args["amount"]
        candy = self.args["candy"]

        # Users shouldn't be able to gift themselves...
        if self.message.author == user:
            return
        invs = database.get_inv(self.server.id, self.author.id, user.id)
        author_candy = invs[self.author.id][candy]
        user_candy = invs[user.id][candy]
        if author_candy < amount:
            await self.send(f"You don't have enough {candy}!")
        elif user_candy >= self.server_settings.cap:
            await self.send(f"{user.mention} cannot obtain any more {candy}!")
        else:
            candy_value = self.calculate_pick(user_candy, CandyValue(candy, amount))
            database.set_inv(self.server.id, self.author.id, -candy_value, update=True)
            database.set_inv(self.server.id, user.id, candy_value, update=True)
            await discord.send_embed(self.message.channel,
                                     f"You have been gifted {candy_value.small_str} by {self.message.author.mention}\n"
                                     f"You now have {(user_candy + candy_value).small_str}",
                                     author=user)
Пример #6
0
 async def _run(self):
     inv = database.get_inv(self.server.id, self.author.id)[self.author.id]
     # Need to obtain the lock to avoid multiple users from picking the candy
     async with engine.STATE_LOCK:
         state = engine.STATE.get(self.channel.id)
         current_candy = inv[state.candy_value.candy] if state else None
         if state and state.command.invocation == self.invocation and current_candy < self.server_settings.cap:
             # This user will pick up the candy drop
             # Must clear the state inside the lock to avoid other users from picking
             del engine.STATE[self.channel.id]
         else:
             # An earlier command was chosen to be processed or the invocation didn't match
             return
     # Code here will be run after the lock is released and should handle the user successfully picking up candy
     await state.message.delete()
     # Replace the dropped candy value to not exceed the candy cap
     state.candy_value = self.calculate_pick(current_candy,
                                             state.candy_value)
     database.set_inv(self.server.id,
                      self.author.id,
                      state.candy_value,
                      update=True)
     await self.send(state.pick_str)
Пример #7
0
 async def _run(self):
     candy_value = CandyValue(self.candy, self.amount)
     database.set_inv(self.message.guild.id, self.user.id, candy_value)
     await discord.send_embed(self.message.channel, f"You now have {candy_value.small_str} (set by {self.message.author.mention})", author=self.user)