class Guild(Model): id = Snowflake(required=True) name = String() owner_id = Snowflake() roles = List(ModelField(Role)) channels = List(ModelField(Channel)) def __init__(self, **kwargs): self.db = kwargs.get('db') self.plugin = kwargs.get('plugin') super(Guild, self).__init__(**kwargs) @property def members(self): pass @property def config(self): return self.plugin.get_config(self) @property def storage(self): return self.plugin.get_guild_storage(self) @property def voice_channels(self): return [c for c in self.channels if c.type == 2] @property def text_channels(self): return [c for c in self.channels if c.type == 0] def __repr__(self): return "<Guild id={} name={}>".format(self.id, self.name)
class Webhook(Model): id = Snowflake(required=True) guild_id = Snowflake() channel_id = Snowflake() name = String() avatar = String() token = String()
class Message(Model): id = Snowflake(required=True) channel_id = Snowflake() content = String() timestamp = String() edited_timestamp = String() author = ModelField(User) webhook_id = Snowflake()
class Member(Model): user = ModelField(User) guild_permissions = Integer(default=0) nick = String() roles = List(Snowflake()) joined_at = String() voice_state = ModelField(VoiceState) def get_voice_channel(self, guild): if not self.voice_state: return None if not self.voice_state.channel_id: return None for vc in guild.voice_channels: if vc.id == self.voice_state.channel_id: return vc return None @property def mention(self): return '<@{}>'.format(self.id) def get_permissions(self, guild): roles = [role for role in guild.roles if role.id in self.roles] return sum(role.permissions for role in roles) def __repr__(self): return "<Member id={} name={}>".format(self.user.id, self.user.username)
class Channel(Model): id = Snowflake(required=True) name = String() type = Integer() position = Integer() @property def mention(self): return '<#{}>'.format(self.id) def __repr__(self): return "<Channel id={} name={}>".format(self.id, self.name)
class VoiceState(Model): guild_id = Snowflake() channel_id = Snowflake() user_id = Snowflake() session_id = String()
class Role(Model): id = Snowflake(required=True) name = String() color = Integer() permissions = Integer()
class CommandConfig(Model): enabled = Boolean(required=True, default=True) global_cooldown = Cooldown() personal_cooldown = Cooldown() allowed_roles = List(Snowflake())
class User(Model): id = Snowflake(required=True) username = String() discriminator = String() avatar = String()
class RedditConfig(Model): subreddits = List(SubredditField()) announcement_channel = Snowflake()
class StreamersConfig(Model): announcement_message = String(max_length=1900) announcement_channel = Snowflake() hitbox_streamers = List(StreamerField()) twitch_streamers = List(StreamerField())