Skip to content

Instantly share code, notes, and snippets.

/plugin.py Secret

Created May 13, 2014 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/a6c334d75c8ae02d82c0 to your computer and use it in GitHub Desktop.
Save anonymous/a6c334d75c8ae02d82c0 to your computer and use it in GitHub Desktop.
supabot plugin
###
# Copyright (c) 2014, dignork
# Licence: WTFPL, grab your copy here: http://sam.zoy.org/wtfpl/
import supybot.utils as utils
from supybot.commands import *
import supybot.plugins as plugins
import supybot.ircutils as ircutils
import supybot.callbacks as callbacks
from supybot import conf
import os,sys
import sqlite3
import hashlib
class Oracle(callbacks.Plugin):
"""Add the help for "@plugin help Oracle" here
This should describe *how* to use this plugin."""
def __init__(self, irc):
self.__parent = super(Oracle, self)
self.__parent.__init__(irc)
self.filename = conf.supybot.directories.data.dirize('puzzles.db')
print 'Going to use', self.filename
if os.path.exists(self.filename):
self.db = sqlite3.connect(self.filename)
else:
self.db = sqlite3.connect(self.filename)
cs = self.db.cursor()
cs.execute("""create table puzzles (id integer primary key, nounce text)""")
cs.close()
def trilema(self, irc, msg, args, c, n, h):
"""<set|list|del|guess> <challenge number> <solution | nounce >"""
if not c in ['set','del','list','guess']:
irc.reply("Dunno what %s is, expecting set list del or guess" % (c))
return
if c in ['set','del','list'] and not msg.prefix in ['mircea_popescu!~Mircea@pdpc/supporter/silver/mircea-popescu',': #todo :add proper ident
irc.reply("You can't %s, %s." % (c,msg.prefix))
return
if c == 'set':
cs = self.db.cursor()
try:
cs.execute('insert into puzzles values (? , ?)', (n,hashlib.sha1(h).hexdigest()))
self.db.commit()
irc.reply("Set #%i as %s" % (n,h) )
except:
irc.reply("Set #%i failed" % (n,) )
cs.close()
if c == 'del':
cs = self.db.cursor()
cs.execute('delete from puzzles where id = ?', (n,))
self.db.commit()
cs.close()
irc.reply("Deleted #%i" % (n,) )
if c == 'list':
cs = self.db.cursor()
cs.execute('select id,nounce from puzzles order by id')
rep = []
dd = cs.fetchall()
for r in dd:
rep.append("%i %s" % (r[0],r[1]))
cs.close()
irc.reply(format('%L', rep))
if c == 'guess':
cs = self.db.cursor()
cs.execute('select nounce from puzzles where id = ?' , (n,))
r = cs.fetchone()
if r is None:
irc.reply("Can't locate puzzle #%i" % (n) )
cs.close()
return
cs.close()
hc = hashlib.sha1(h).hexdigest()
gr = "but No"
if hc == r[0]:
gr = "and You actually guessed correctly!"
irc.reply("Your guess for puzzle #%i %s, %s" % (n,h,gr) )
trilema = wrap(trilema, ['something','int',additional('text')])
Class = Oracle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment