def add_or_update_channel(self, channel_id: str, message_id: str): item: PinMap = self.find_channel_by_id(channel_id) if item is None: item = PinMap(channel_id=channel_id, message_id=message_id) session.add(item) else: item.message_id = message_id session.commit()
def add_vote(self, message_id: int, channel_id: int, ends_at: Optional[datetime], is_one_of: bool = False): vote = Vote(message_id=message_id, channel_id=channel_id, ends_at=ends_at, is_one_of=is_one_of) session.add(vote) session.commit()
def create_repost(original_message_id: int, repost_message_id: int, author_id: int, secondary_repost_message_id: int = None): item = MemeRepost( original_message_id=str(original_message_id), reposted_message_id=str(repost_message_id), author_id=str(author_id), secondary_repost_message_id=str(secondary_repost_message_id)) session.add(item) session.commit()
def create_subscriber(user: Union[discord.User, discord.Member], reminder_id: int) -> ReminderSubscriber: if not UserRepo.user_exist(user.id): UserRepo.create_user(user) item = ReminderSubscriber(reminder_id=reminder_id, user_id=str(user.id)) session.add(item) session.commit() return item
async def connect_login_to_user(self, ctx, login, member: discord.Member): result = session.query(Valid_person).\ filter(Valid_person.login == login).one_or_none() if result is None: await ctx.send("To není validní login.") else: session.add(Permit(login=login, discord_ID=str(member.id))) result.status = 0 session.commit() await ctx.send("Hotovo.")
def add_rule(self, guild_id: int, command: str, allow: bool = False) -> ACL_rule: if self.get_rule(guild_id, command) is not None: raise Duplicate(guild_id=guild_id, command=command) rule = ACL_rule(guild_id=guild_id, command=command, default=allow) session.add(rule) session.commit() return rule
def create_repost_settings(guild:discord.Guild, repost_channel_id: int) -> Optional[RepostSeting]: if RepostSettingsRepo.get_repost_settings(guild.id) is not None: return None if not GuildRepo.guild_exist(guild.id): GuildRepo.create_guild(guild) item = RepostSeting(guild_id=str(guild.id), repost_channel_id=str(repost_channel_id)) session.add(item) session.commit() return item
def __create_empty(guild: discord.Guild): if not GuildRepo.guild_exist(guild.id): GuildRepo.create_guild(guild) item = WelcomeMessageConfig(guild_id=str(guild.id), welcome_message_enable=False, welcome_message_channel_id=None, welcome_message=None) session.add(item) session.commit() return item
def add_image(cls, channel_id: int, message_id: int, attachment_id: int, dhash: str): """Add new image hash""" session.add( Image( channel_id=channel_id, message_id=message_id, attachment_id=attachment_id, dhash=dhash, timestamp=datetime.datetime.now().replace(microsecond=0), )) session.commit()
def __create_reward(probability: float, item: Optional[Union[Item, int]] = None, xp: Optional[int] = None, money: Optional[int] = None, write: bool = True): reward_it = Reward(aquire_prob=probability, item_id=item, xp=xp, money=money) session.add(reward_it) if write: session.commit() return reward_it
def add(guild_id: int, author_id: int, user_id: int, text: str): """Add user comment""" query = Comment( guild_id=guild_id, author_id=author_id, user_id=user_id, text=text, timestamp=datetime.now(), ) session.add(query) session.commit() return query
def __create_emoji(emoji:Union[discord.Emoji, discord.PartialEmoji, str], guild:discord.Guild) -> Karma: if not GuildRepo.guild_exist(guild.id): GuildRepo.create_guild(guild) emoji_id = general_util.emoji_id_from_emoji(emoji) if not EmojiDataRepo.emoji_data_exist(emoji_id): EmojiDataRepo.create_emoji_data(emoji) with emoji_access_lock: item = Karma_emoji(emoji_ID=emoji_id, guild_id=str(guild.id)) session.add(item) session.commit() return item
def add(self, discord_id: int, login: str, group: str, code: str, status: str = "pending"): """Add new user""" user = User( discord_id=discord_id, login=login, group=group, code=code, status=status, changed=time(), ) session.add(user) session.commit() return user
def add_review(self, author, subject, tier, anonym: bool, text): try: review = Review(member_ID=str(author), subject=subject, tier=tier, anonym=anonym, text_review=text, date=datetime.date.today()) session.add(review) session.commit() except Exception: session.rollback() raise
def create_action(user: Union[discord.Member, discord.User], action: Union[ActionsEnum, int], end_date: datetime, additional_data: Optional[str] = None) -> Action: if isinstance(action, ActionsEnum): action = action.value PlayerRepo.get_player(user) item = Action(player_id=str(user.id), action_id=action, end_date=end_date, special_data=additional_data) session.add(item) session.commit() return item
def add(self, guild_id: int, channel_id: int, name: str) -> AnonsendChannel: if self.get(name=name) is not None: raise ValueError(f"Name {name} already exists.") result = AnonsendChannel( guild_id=guild_id, channel_id=channel_id, name=name, count=0, ) session.add(result) session.commit() return result
def add(cls, emote: discord.Emoji): """Add new emote""" db_emote = session.query(Emote).filter( Emote.emote_id == emote.id).one_or_none() if db_emote is None: session.add( Emote( emote_id=emote.id, guild_id=emote.guild_id, name=emote.name, animated=emote.animated, original_name=emote.name, )) session.commit()
def add_attachment(message: discord.Message, attachment: discord.Attachment, dhash: str, write: bool = True): if WardenRepo.attachment_exist(message.id): return item = WardenAttachment(attachment_id=str(attachment.id), message_id=str(message.id), channel_id=str(message.channel.id), dhash=dhash, message_created_at=message.created_at, guild_id=str(message.guild.id)) session.add(item) if write: session.commit()
def create_guild_user(member: discord.Member) -> GuildUser: if not UserRepo.user_exist(member.id): UserRepo.create_user(member) if not GuildRepo.guild_exist(member.guild.id): GuildRepo.create_guild(member.guild) item = GuildUser(display_name=member.display_name, id=str(member.id), guild_id=str(member.guild.id), joined_at=member.joined_at) session.add(item) session.commit() return item
def add_group(self, guild_id: int, name: str, parent: str, role_id: int) -> ACL_group: if parent is not None and self.get_group(guild_id, parent) is None: raise NotFound(guild_id=guild_id, name=parent) if self.get_group(guild_id, name) is not None: raise Duplicate(guild_id=guild_id, name=name) if role_id > 0 and self.get_group_by_role(role_id) is not None: raise Duplicate(role_id=role_id) group = ACL_group(guild_id=guild_id, name=name, parent=parent, role_id=role_id) session.add(group) session.commit() return group
def create(self, subject: str, link: str, username: str, description: str, thumbnail_url: str, created_at: datetime): try: streamlink = StreamLink(subject=subject, link=link, member_name=username, description=description, thumbnail_url=thumbnail_url, created_at=created_at) session.add(streamlink) session.commit() except: # noqa: E722 session.rollback() raise
def __create_guild_emoji_stats_for_emoji( guild: discord.Guild, emoji: Union[discord.Emoji, discord.PartialEmoji, str]) -> GuildEmojiStats: if not GuildRepo.guild_exist(guild.id): GuildRepo.create_guild(guild) emoji_id = general_util.emoji_id_from_emoji(emoji) if not EmojiDataRepo.emoji_data_exist(emoji_id): EmojiDataRepo.create_emoji_data(emoji) item = GuildEmojiStats(guild_id=str(guild.id), emoji_id=emoji_id) session.add(item) session.commit() return item
def add_image(self, channel_id: int, message_id: int, attachment_id: int, dhash: str): """Add new image hash""" if self.getByAttachment(attachment_id) is not None: # attachment already indexed return session.add( Image( channel_id=channel_id, message_id=message_id, attachment_id=attachment_id, dhash=dhash, )) session.commit()
def add( self, discord_id: int, login: str, group: str, code: str, ): """Add new user""" session.add( User( discord_id=discord_id, login=login, group=group, code=code, status="pending", changed=time(), ) ) session.commit()
def add_role(self, acl_group_id, role_id_name, perms): # TODO check group id validity try: int(role_id_name) role_id = role_id_name role_name = None except ValueError: role_id = None role_name = role_id_name rule = Acl_role_binding(acl_group_id=acl_group_id, role_id=role_id, role_name=role_name, perms=perms) session.add(rule) session.commit()
def add_image(self, channel_id: int, message_id: int, attachment_id: int, dhash: str): """Add new image hash""" if self.getByAttachment(attachment_id) is not None: # attachment already indexed return session.add( Image( channel_id=channel_id, message_id=message_id, attachment_id=attachment_id, dhash=dhash, timestamp=datetime.datetime.now().replace(microsecond=0), )) session.commit()
def set_birthday(user: Union[discord.Member, discord.User], date: datetime.date, year: int, write: bool = True): if not UserRepo.user_exist(user.id): UserRepo.create_user(user) item = BirthdayRepo.find_by_id(user.id) if item is None: item = BirthdayItem(user_id=str(user.id), date=date, year=year) session.add(item) session.commit() else: item.date = date if write: session.commit()
def add(self, guild_id: int, user_id: int, end_time: datetime): """Adds tempverify to the database""" tempverify = session.query(Tempverify).filter_by( user_id=user_id).one_or_none() if not tempverify: added = Tempverify( guild_id=guild_id, user_id=user_id, end_time=end_time, ) session.add(added) session.commit() else: added = None return added
def add_review(self, author, subject, tier, anonym: bool, text) -> Review: try: review = Review( discord_id=str(author), subject=subject, tier=tier, anonym=anonym, text_review=text, date=datetime.date.today(), ) session.add(review) session.commit() except Exception: session.rollback() raise return review
def slap(self, guild_id: int, giver: int, receiver: int): user_g = self.get(guild_id, giver) user_r = self.get(guild_id, receiver) if user_g is None: user_g = session.add( Meme(user_id=giver, guild_id=guild_id, slaps_gave=1)) else: user_g.slaps_gave += 1 if user_r is None: user_r = session.add( Meme(user_id=receiver, guild_id=guild_id, slaps_recv=1)) else: user_r.slaps_recv += 1 session.commit()