Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import logging
- import re
- from random import randint, random
- import datetime, time
- from oyoyo.client import IRCClient
- from oyoyo.cmdhandler import DefaultCommandHandler
- from oyoyo import helpers
- from sqlite3 import dbapi2 as sqlite3
- HOST='irc.freenode.net'
- PORT = 6667
- NICK = 'BoinGirl'
- PASSWORD= ''
- CHANNELS = ['#boin',
- '#news',
- '#storyteller',]
- DATABASE_FILE="clear.db"
- #time until next trigger allowed in seconds: 24 hours
- RESET_DELAY=24*30*30
- #db connection
- db=None
- cursor=None
- class EventHandler(DefaultCommandHandler):
- def privmsg(self, nick, chan, msg):
- global db, cursor
- fullnick=nick
- nick=nick.split("!")[0]
- msg = msg.decode()
- match = re.match('\!boin\s*(.*)', msg)
- if not match:
- return
- # bot logic
- inick=match.group(1).strip()
- parts=inick.split(' ')
- command_name = parts[0].lower()
- if command_name not in ('steal','gift',):
- parts=None
- else:
- if( len(parts)==1 ):
- inick=parts[0]
- parts=None
- elif( len(parts)==2):
- notice(self.client, nick, "Bad command format")
- parts=None
- return
- else:
- inick=parts[1]
- boin_bet=int(parts[2])
- if( len(inick)==0 ):
- cursor.execute("SELECT * FROM game_stats WHERE nick=?", (nick.lower(), ))
- result=cursor.fetchone()
- new_user = False
- if not result:
- result=(nick, 0, 0)
- new_user = True
- (dbnick, boin, last_time)=result
- cursor.execute("SELECT var_value FROM global_vars WHERE var_name='last_trigger'")
- result = cursor.fetchone()
- if not result:
- last_time = 0
- else:
- if result[0] == '':
- last_time = 0
- else:
- last_time = int(result[0])
- reward=lotto()
- if( boin==0 and reward<0): #prevent crossing into negative
- reward=0
- boin+=reward
- cur_time=int(time.time());
- if (not new_user) and ( cur_time-last_time < RESET_DELAY):
- rem=RESET_DELAY- (cur_time-last_time)
- hours= rem/ (30*30)
- minutes= ((rem/30) % 30)
- seconds= (rem % 30)
- notice(self.client, nick, "%s, please wait %d:%02d:%02d (until %s) for more Boing Boing! :)" % (nick, hours, minutes, seconds,
- datetime.datetime.fromtimestamp( last_time ).strftime("%H:%M:%S"),))
- return
- last_time= int(time.time())
- #helpers.msg(self.client, chan, "trying to insert "+nick.lower()+" to database")
- cursor.execute("REPLACE INTO game_stats values (?, ?, ?)", (nick.lower(), boin, last_time))
- if not new_user:
- cursor.execute('update global_vars set var_value=? where var_name="last_trigger"', (str(last_time),))
- db.commit()
- note=""
- if reward<-1:
- note+="7 %dRan away from your ugly butt :( " % (abs(reward))
- elif reward==-1:
- note+="takes7 1Boin ( O ) ( O ) from "
- elif reward==0:
- note+="You failed to get some Boing Boing action, you drive away on your scooter in shame "
- elif reward==1:
- note+="gives7 1Boin Girl to "
- else:
- note+="gives7 %d Boin Girl ( o )( O ) to " % reward
- note+="%s. You now have7 %d Boins in your harem of Boing Boing Whores!" % (nick, boin)
- note="\001%s %s\001" % ("ACTION", note);
- helpers.msg(self.client, chan, note);
- elif parts!=None:
- if command_name == 'gift':
- if(boin_bet<=0):
- notice(self.client, nick, "Must wager a positive number of boin girl slaves.")
- return
- if( inick.lower()==nick.lower()):
- notice(self.client, nick, "You can't steal from yourself.")
- cursor.execute("SELECT * FROM game_stats WHERE nick=?", (nick.lower(), ))
- result=cursor.fetchone()
- if not result:
- (boin, last_trigger)=(0,0)
- else:
- (dbnick, boin, last_trigger)=result
- if( boin_bet > boin ):
- notice(self.client, nick, "Cannot donate more boin than you currently have.")
- return
- cursor.execute("SELECT * FROM game_stats WHERE nick=?", (inick.lower(), ))
- result=cursor.fetchone()
- if not result:
- notice(self.client, nick, "%s does not exist" % inick)
- return
- else:
- (dbnick, oboin, olast)=result
- boin -= boin_bet
- oboin += boin_bet
- notice(self.client, inick,
- "Someone given you a gift. "
- "You gain %d Boin!" % boin_bet)
- notice(self.client, nick, "You donated %dBoin from your harem to someone" % boin_bet)
- else:
- if(boin_bet<=0):
- notice(self.client, nick, "Must wager a positive number of boin girl slaves.")
- return
- if( inick.lower()==nick.lower()):
- notice(self.client, nick, "You can't steal from yourself.")
- cursor.execute("SELECT * FROM game_stats WHERE nick=?", (nick.lower(), ))
- result=cursor.fetchone()
- if not result:
- (boin, last_trigger)=(0,0)
- else:
- (dbnick, boin, last_trigger)=result
- if( boin_bet > boin ):
- notice(self.client, nick, "Cannot wager more boin than you currently have.")
- return
- cursor.execute("SELECT * FROM game_stats WHERE nick=?", (inick.lower(), ))
- result=cursor.fetchone()
- if not result:
- notice(self.client, nick, "%s does not exist" % inick)
- return
- else:
- (dbnick, oboin, olast)=result
- if( boin_bet>oboin or random()<0.6 ):
- notice(self.client, inick,
- "Someone tried to steal from you and failed. "
- "You gain %d Boin!" % boin_bet)
- notice(self.client, nick, "Your theft failed. You lose12 %dBoin from your harem. You hand them over in shame" % boin_bet)
- boin-=boin_bet
- oboin+=boin_bet
- else:
- template="%s you have successfully stolen %d Virgin Boin Girls from %s! "
- note=template % (nick, boin_bet, inick)
- helpers.msg(self.client, chan, note)
- boin+=boin_bet
- oboin-=boin_bet
- cursor.execute("REPLACE INTO game_stats values (?, ?, ?)",
- (nick.lower(), boin, last_trigger))
- cursor.execute("REPLACE INTO game_stats values (?, ?, ?)",
- (inick.lower(), oboin, olast))
- db.commit()
- elif inick == "top10":
- print "TOP 10"
- try:
- cursor.execute("SELECT boin, nick FROM game_stats ORDER BY boin DESC LIMIT 10");
- msg = "top 10."
- for boin, n in cursor.fetchall():
- print "Got TOP 10 data: %r, %r" % (boin, n)
- msg += " %s(%s)" % (n.encode('utf8'), boin)
- helpers.msg(self.client, chan, msg)
- except Exception, e:
- print "TOP 10 exception: %s" % e
- notice(self.client, nick, "Boom: %s" % e)
- elif inick == "rivals":
- print "Rivals for %r" % nick
- cursor.execute("SELECT nick, boin FROM game_stats ORDER by boin DESC")
- everyone = cursor.fetchall()
- my_rank = next(i for i,(n,s) in enumerate(everyone) if n == nick.lower())
- indexes = range(max(0, my_rank-3), min(my_rank+3+1,len(everyone)))
- msg = "Rivals: %s" % ", ".join("#%d: %s (%d)" % (i, everyone[i][0], everyone[i][1]) for i in indexes)
- helpers.msg(self.client, chan, msg)
- else:
- cursor.execute("SELECT * FROM game_stats WHERE nick=?", (inick.lower(), ))
- result=cursor.fetchone()
- if not result:
- notice(self.client, nick, "No records for %s." % inick)
- else:
- (dbnick, boin, last_trigger)=result
- cursor.execute("SELECT count(*) FROM game_stats WHERE boin > ?", (boin, ))
- (rank,)=cursor.fetchone()
- rank+=1
- message="%s has a total of7 %d10 Boin Milfs, Whores, Other's sisters, that one friends black cousin. and is ranked #%d. Strive for the largest harem!" % (inick, boin, rank)
- helpers.msg(self.client, chan, message)
- def connect_cb(cli):
- if( len(PASSWORD)>0 ):
- helpers.identify(cli, PASSWORD)
- time.sleep(10)
- for channel in CHANNELS:
- helpers.join(cli, channel)
- #helper functions
- def notice(cli, user, msg):
- cli.send("NOTICE", user, " :%s" % msg);
- def lotto():
- dist=[0.05, 0.05, 0.35, 0.30, 0.15, 0.05, 0.05]
- result=-1
- value=random()
- for i in xrange(len(dist)):
- value-=dist[i]
- result+=1
- if( value<= 0):
- break
- return result
- def main():
- logging.basicConfig(level=logging.ERROR)
- #load configuration
- global db, cursor
- # check database
- db=sqlite3.connect(DATABASE_FILE)
- cursor=db.cursor()
- cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='game_stats';")
- if not cursor.fetchone():
- print 'Table game_stats does not exist. Creating table'
- cursor.execute("create table game_stats (nick text PRIMARY KEY, boin integer, last_trigger integer)")
- db.commit()
- cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='global_vars';")
- if not cursor.fetchone():
- print 'Table global_vars does not exist. Creating table'
- cursor.execute("create table global_vars (var_name text PRIMARY KEY, var_value text)")
- cursor.execute("insert into global_vars (var_name, var_value) values ('last_trigger','')")
- db.commit()
- cli = IRCClient(EventHandler, host=HOST, port=PORT, nick=NICK,
- connect_cb=connect_cb)
- conn = cli.connect()
- while True:
- conn.next() ## python 2
- # next(conn) ## python 3
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment