From: matthew Date: Wed, 6 Feb 2002 18:52:34 +0000 (+0000) Subject: added quota functionality, and removed disconnect X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~matthewv/git?p=irc.git;a=commitdiff_plain;h=9aa26e36cb612b063282fe39db3216ac1e7cfcf3 added quota functionality, and removed disconnect --- diff --git a/acrobat-chiark-0.2.py b/acrobat-chiark-0.2.py index 7469ae7..0d9757d 100755 --- a/acrobat-chiark-0.2.py +++ b/acrobat-chiark-0.2.py @@ -33,7 +33,7 @@ back with the url. """ -import string, urllib, sys, cPickle, os, random, re +import string, urllib, sys, cPickle, os, random, re, time from ircbot import SingleServerIRCBot from irclib import nm_to_n, irc_lower @@ -49,6 +49,14 @@ class Acrobat(SingleServerIRCBot): [(server, port)], nickname, nickname) self.channel = channel self.owner = owner + self.quotatime = time.time() + #Configurable stuff - how often do we add how many fish? + self.cur_fish=5 + self.max_fish=5 #Maximum of 5 fish + self.fish_time_inc=60 #Add fish with 20s granularity + self.fish_inc=2 #Rate of increase is 2 fish per 60s + self.DoS=0 #Have we been told to shut up? + self.Boring_Git='Nobody' #Who told us to shut up? # load the karma db try: f = open("karmadump", "r") @@ -153,6 +161,15 @@ class Acrobat(SingleServerIRCBot): # trout someone def troutq(self, cmd, nick, conn, public): + self.fish_quota() + if self.DoS == 1: + conn.notice(nick, "Sorry, but %s is being a spoilsport." % + self.Boring_Git) + return + if self.cur_fish == 0: + conn.notice(nick, "Fish stocks exhausted.") + else: + self.cur_fish -=1 try: target = string.join(cmd.split()[1:]) me = self.connection.get_nickname() @@ -184,6 +201,27 @@ class Acrobat(SingleServerIRCBot): self.trouts = tback else: conn.notice(nick, "This command can only be invoked by my owner.") + # Shut up trouting for a minute + def nofish(self, cmd, nick, conn, public): + self.cur_fish=0 + self.DoS=1 + self.Boring_Git=nick + self.quotatime=time.time() + self.quotatime+=60 #60 seconds of no fishing + conn.notice(nick, "Fish stocks depleted, as you wish.") + # Check on fish stocks + def fish_quota(self): + if self.DoS==1: + if time.time()>=self.quotatime: + self.DoS=0 + else: + return + if self.DoS==0: + if (time.time()-self.quotatime)>self.fish_time_inc: + self.cur_fish+=(((time.time()-self.quotatime)/self.fish_time_inc)*self.fish_inc) + if self.cur_fish>self.max_fish: + self.cur_fish=self.max_fish + self.quotatime=time.time() # quit irc def quit(self, cmd, nick, conn, public): @@ -246,11 +284,16 @@ class Acrobat(SingleServerIRCBot): self.troutq(cmd, nick, conn, public) if cmd == "reload": self.reloadq(cmd, nick, conn, public) - - #disconnect - if cmd == "disconnect": # hop off for 60s - self.disconnect(msg="Be right back.") +#Disconnect disabled 'cos people hated it +# #disconnect +# if cmd == "disconnect": # hop off for 60s +# self.disconnect(msg="Be right back.") + + # No more trout + if cmd.split()[0] == "quiet": + self.nofish(cmd,nick,conn, public) + # say to msg/channel elif cmd.split()[0] == "say" \ and irc_lower(nick) == irc_lower(self.owner):