Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import Iterable
- class Checks:
- """Class of predicates for waiting events
- This class requires you to pass ctx so that the person who
- invocated the command can be determined.
- You may pass an optional iterable in custom to check if the
- content is a member of it."""
- def __init__(self, ctx, custom: Iterable = None):
- self.ctx = ctx
- self.custom = custom
- def confirm(self, m):
- return self.ctx.author == m.author and m.content.lower() in ('yes', 'no')
- def valid_int(self, m):
- return self.ctx.author == m.author and m.content.isdigit()
- def positive(self, m):
- return self.ctx.author == m.author and m.content.isdigit() and int(m.content) > 0
- def role(self, m):
- roles = [r.name for r in self.ctx.guild.roles if r.name != "Bot"]
- return self.ctx.author == m.author and m.content in roles
- def member(self, m):
- return self.ctx.author == m.author and m.content in [x.name for x in self.ctx.guild.members]
- def content(self, m):
- if self.content is not None:
- return self.ctx.author == m.author and m.content in self.custom
- else:
- raise ValueError("Custom must be set for this check.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement