Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. from collections import Iterable
  2.  
  3.  
  4. class Checks:
  5.     """Class of predicates for waiting events
  6.  
  7.    This class requires you to pass ctx so that the person who
  8.    invocated the command can be determined.
  9.  
  10.    You may pass an optional iterable in custom to check if the
  11.    content is a member of it."""
  12.  
  13.     def __init__(self, ctx, custom: Iterable = None):
  14.         self.ctx = ctx
  15.         self.custom = custom
  16.  
  17.     def confirm(self, m):
  18.         return self.ctx.author == m.author and m.content.lower() in ('yes', 'no')
  19.  
  20.     def valid_int(self, m):
  21.         return self.ctx.author == m.author and m.content.isdigit()
  22.  
  23.     def positive(self, m):
  24.         return self.ctx.author == m.author and m.content.isdigit() and int(m.content) > 0
  25.  
  26.     def role(self, m):
  27.         roles = [r.name for r in self.ctx.guild.roles if r.name != "Bot"]
  28.         return self.ctx.author == m.author and m.content in roles
  29.  
  30.     def member(self, m):
  31.         return self.ctx.author == m.author and m.content in [x.name for x in self.ctx.guild.members]
  32.  
  33.     def content(self, m):
  34.         if self.content is not None:
  35.             return self.ctx.author == m.author and m.content in self.custom
  36.         else:
  37.             raise ValueError("Custom must be set for this check.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement