def save(self): session = Session() session.add(self) try: session.commit() return True except InvalidRequestError: return False
def saveServer(serverId: str, channelId: str = None): session = Session() server = getServerById(serverId, session) if server is None: server = Server(id=serverId, role_reaction_channel_id=channelId) session.add(server) elif channelId is not None: setattr(server, 'role_reaction_channel_id', channelId) session.commit()
def saveKarmaReaction(serverId: str, reaction: str, change: int): session = Session() karmaReaction = getKarmaReactionByServerAndReaction( serverId, reaction, session) if karmaReaction is None: karmaReaction = KarmaReaction(reaction=reaction, server_id=serverId, karmaChange=change) session.add(karmaReaction) else: karmaReaction.karmaChange = change session.commit()
def incUserMsgCount(user): ses = Session() dbUser = getUserById(str(user.id), ses) if dbUser is None: dbUser = User(message_count=1, karma=0, name=str(user), id=str(user.id)) ses.add(dbUser) else: dbUser.message_count += 1 ses.commit()