コード例 #1
0
ファイル: karma.py プロジェクト: MiCurry/hamper
        def command(self, bot, comm, groups):
            kt = bot.factory.loader.db.session.query(KarmaStatsTable)
            counter = Counter()

            if groups[0] == "giver":
                positive_karma = kt.filter(KarmaStatsTable.kcount > 0)
                for row in positive_karma:
                    counter[row.giver] += row.kcount

                m = counter.most_common(1)
                most = m[0] if m else None
                if most:
                    bot.reply(comm, "%s has given the most karma (%d)" % (uen(most[0]), most[1]))
                else:
                    bot.reply(comm, "No positive karma has been given yet :-(")
            elif groups[0] == "taker":
                negative_karma = kt.filter(KarmaStatsTable.kcount < 0)
                for row in negative_karma:
                    counter[row.giver] += row.kcount

                m = counter.most_common()
                most = m[-1] if m else None
                if most:
                    bot.reply(comm, "%s has given the most negative karma (%d)" % (uen(most[0]), most[1]))
                else:
                    bot.reply(comm, "No negative karma has been given yet")
コード例 #2
0
ファイル: karma.py プロジェクト: mohamedotnet/hamper
        def command(self, bot, comm, groups):
            kt = bot.factory.loader.db.session.query(KarmaStatsTable)
            counter = Counter()

            if groups[0] == 'giver':
                positive_karma = kt.filter(KarmaStatsTable.kcount > 0)
                for row in positive_karma:
                    counter[row.giver] += row.kcount

                m = counter.most_common(1)
                most = m[0] if m else None
                if most:
                    bot.reply(
                        comm, '%s has given the most karma (%d)' %
                        (uen(most[0]), most[1]))
                else:
                    bot.reply(comm, 'No positive karma has been given yet :-(')
            elif groups[0] == 'taker':
                negative_karma = kt.filter(KarmaStatsTable.kcount < 0)
                for row in negative_karma:
                    counter[row.giver] += row.kcount

                m = counter.most_common()
                most = m[-1] if m else None
                if most:
                    bot.reply(
                        comm, '%s has given the most negative karma (%d)' %
                        (uen(most[0]), most[1]))
                else:
                    bot.reply(comm, 'No negative karma has been given yet')
コード例 #3
0
        def command(self, bot, comm, groups):
            # Play nice when the user isn't in the db
            kt = bot.factory.loader.db.session.query(KarmaTable)
            thing = ude(groups[0].strip().lower())
            user = kt.filter(KarmaTable.user == thing).first()

            if user:
                bot.reply(comm,
                          '%s has %d points' % (uen(user.user), user.kcount),
                          encode=False)
            else:
                bot.reply(comm, 'No karma for %s ' % uen(thing), encode=False)
コード例 #4
0
ファイル: karma.py プロジェクト: a-harper/hamper
        def command(self, bot, comm, groups):
            # Play nice when the user isn't in the db
            kt = bot.factory.loader.db.session.query(KarmaTable)
            thing = ude(groups[0].strip().lower())
            user = kt.filter(KarmaTable.user == thing).first()

            if user:
                bot.reply(
                    comm, '%s has %d points' % (uen(user.user), user.kcount),
                    encode=False
                )
            else:
                bot.reply(
                    comm, 'No karma for %s ' % uen(thing), encode=False
                )
コード例 #5
0
ファイル: karma.py プロジェクト: mohamedotnet/hamper
        def command(self, bot, comm, groups):
            # The receiver (or in old terms, user) of the karma being tallied
            receiver = ude(groups[0].strip().lower())

            # Manage both tables
            sesh = bot.factory.loader.db.session

            # Old Table
            kt = sesh.query(KarmaTable)
            user = kt.filter(KarmaTable.user == receiver).first()

            # New Table
            kst = sesh.query(KarmaStatsTable)
            kst_list = kst.filter(KarmaStatsTable.receiver == receiver).all()

            # The total amount of karma from both tables
            total = 0

            # Add karma from the old table
            if user:
                total += user.kcount

            # Add karma from the new table
            if kst_list:
                for row in kst_list:
                    total += row.kcount

            # Send the message
            bot.reply(comm,
                      '%s has %d points' % (uen(receiver), total),
                      encode=False)
コード例 #6
0
ファイル: karma.py プロジェクト: MiCurry/hamper
        def command(self, bot, comm, groups):
            # The receiver (or in old terms, user) of the karma being tallied
            receiver = ude(groups[0].strip().lower())

            # Manage both tables
            sesh = bot.factory.loader.db.session

            # Old Table
            kt = sesh.query(KarmaTable)
            user = kt.filter(KarmaTable.user == receiver).first()

            # New Table
            kst = sesh.query(KarmaStatsTable)
            kst_list = kst.filter(KarmaStatsTable.receiver == receiver).all()

            # The total amount of karma from both tables
            total = 0

            # Add karma from the old table
            if user:
                total += user.kcount

            # Add karma from the new table
            if kst_list:
                for row in kst_list:
                    total += row.kcount

            # Pluralization
            points = "points"
            if total == 1 or total == -1:
                points = "point"

            # Send the message
            bot.reply(comm, "%s has %d %s" % (uen(receiver), total, points), encode=False)
コード例 #7
0
        def command(self, bot, comm, groups):
            # Let the database restrict the amount of rows we get back.
            # We can then just deal with a few rows later on
            session = bot.factory.loader.db.session
            kcount = func.sum(KarmaStatsTable.kcount).label('kcount')
            kts = session.query(KarmaStatsTable.receiver, kcount) \
                         .group_by(KarmaStatsTable.receiver)

            # For legacy support
            classic = session.query(KarmaTable)

            # Counter for sorting and updating data
            counter = Counter()

            if kts.count() or classic.count():
                # We should limit the list of users to at most self.LIST_MAX
                if groups[0] == 'top':
                    classic_q = classic.order_by(KarmaTable.kcount.desc())\
                                       .limit(self.LIST_MAX).all()
                    query = kts.order_by(kcount.desc())\
                               .limit(self.LIST_MAX).all()

                    counter.update(dict(classic_q))
                    counter.update(dict(query))
                    snippet = counter.most_common(self.LIST_MAX)
                elif groups[0] == 'bottom':
                    classic_q = classic.order_by(KarmaTable.kcount)\
                                       .limit(self.LIST_MAX).all()
                    query = kts.order_by(kcount)\
                               .limit(self.LIST_MAX).all()
                    counter.update(dict(classic_q))
                    counter.update(dict(query))
                    snippet = reversed(counter.most_common(self.LIST_MAX))
                else:
                    bot.reply(
                        comm, r'Something went wrong with karma\'s regex'
                    )
                    return

                for rec in snippet:
                    bot.reply(
                        comm, '%s\x0f: %d' % (uen(rec[0]), rec[1]),
                        encode=False
                    )
            else:
                bot.reply(comm, 'No one has any karma yet :-(')
コード例 #8
0
ファイル: karma.py プロジェクト: demophoon/hamper
        def command(self, bot, comm, groups):
            # Let the database restrict the amount of rows we get back.
            # We can then just deal with a few rows later on
            session = bot.factory.loader.db.session
            kcount = func.sum(KarmaStatsTable.kcount).label('kcount')
            kts = session.query(KarmaStatsTable.receiver, kcount) \
                         .group_by(KarmaStatsTable.receiver)

            # For legacy support
            classic = session.query(KarmaTable)

            # Counter for sorting and updating data
            counter = Counter()

            if kts.count() or classic.count():
                # We should limit the list of users to at most self.LIST_MAX
                if groups[0] == 'top':
                    classic_q = classic.order_by(KarmaTable.kcount.desc())\
                                       .limit(self.LIST_MAX).all()
                    query = kts.order_by(kcount.desc())\
                               .limit(self.LIST_MAX).all()

                    counter.update(dict(classic_q))
                    counter.update(dict(query))
                    snippet = counter.most_common(self.LIST_MAX)
                elif groups[0] == 'bottom':
                    classic_q = classic.order_by(KarmaTable.kcount)\
                                       .limit(self.LIST_MAX).all()
                    query = kts.order_by(kcount)\
                               .limit(self.LIST_MAX).all()
                    counter.update(dict(classic_q))
                    counter.update(dict(query))
                    snippet = reversed(counter.most_common(self.LIST_MAX))
                else:
                    bot.reply(
                        comm, r'Something went wrong with karma\'s regex'
                    )
                    return

                for rec in snippet:
                    bot.reply(
                        comm, '%s\x0f: %d' % (uen(rec[0]), rec[1]),
                        encode=False
                    )
            else:
                bot.reply(comm, 'No one has any karma yet :-(')
コード例 #9
0
ファイル: quote.py プロジェクト: mythmon/hamper
 def command(self, bot, comm, groups):
     index = random.randrange(0, bot.db.session.query(Quote).count())
     quote = bot.factory.loader.db.session.query(Quote)[index]
     bot.reply(comm, uen(quote.text))
     return True
コード例 #10
0
ファイル: quotes.py プロジェクト: MiCurry/hamper
 def command(self, bot, comm, groups):
     index = random.randrange(0, bot.db.session.query(Quote).count())
     quote = bot.factory.loader.db.session.query(Quote)[index]
     bot.reply(comm, uen(quote.text))
     return True