コード例 #1
0
 def save(self):
     session = Session()
     session.add(self)
     try:
         session.commit()
         return True
     except InvalidRequestError:
         return False
コード例 #2
0
ファイル: serverRepo.py プロジェクト: ZemanOndrej/pepega-bot
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()
コード例 #3
0
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()
コード例 #4
0
ファイル: userRepo.py プロジェクト: ZemanOndrej/pepega-bot
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()