More commenting, deteted junkfiles
This commit is contained in:
parent
40091588e4
commit
3600c715b6
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,21 @@
|
||||||
|
:mod:`AttributeStorage` --- Item key/value storage
|
||||||
|
==================================================
|
||||||
|
|
||||||
|
Item key->value storage engine based on mysql. Provides a service called
|
||||||
|
`attributes` that stores items.
|
||||||
|
|
||||||
|
Items are dicts. An item can have many keys. Each key points to one value.
|
||||||
|
|
||||||
|
.. code-block:: text
|
||||||
|
|
||||||
|
[ item ] --+--> [ key ] --> [ value ]
|
||||||
|
|
|
||||||
|
+--> [ key ] --> [ value ]
|
||||||
|
|
|
||||||
|
+--> [ key ] --> [ value ]
|
||||||
|
|
||||||
|
|
||||||
|
.. automodule:: modules.AttributeStorage
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
|
@ -0,0 +1,9 @@
|
||||||
|
:mod:`CryptoWallet` --- BitcoinD RPC Service
|
||||||
|
============================================
|
||||||
|
|
||||||
|
Module to provide a multi-type cryptocurrency wallet
|
||||||
|
|
||||||
|
.. automodule:: modules.CryptoWallet
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
|
@ -0,0 +1,9 @@
|
||||||
|
:mod:`CryptoWalletRPC` --- BitcoinD RPC Service
|
||||||
|
===============================================
|
||||||
|
|
||||||
|
Module capable of operating Bitcoind-style RPC. Provided as a service.
|
||||||
|
|
||||||
|
.. automodule:: modules.CryptoWalletRPC
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
|
@ -0,0 +1,9 @@
|
||||||
|
:mod:`DogeDice` --- A dogecoin game
|
||||||
|
===================================
|
||||||
|
|
||||||
|
Module to provide a game for gambling Dogecoin
|
||||||
|
|
||||||
|
.. automodule:: modules.DogeDice
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
|
@ -0,0 +1,9 @@
|
||||||
|
:mod:`DogeRPC` --- A dogecoind RPC service
|
||||||
|
==========================================
|
||||||
|
|
||||||
|
This module provides a service for interacting with dogecoind.
|
||||||
|
|
||||||
|
.. automodule:: modules.DogeRPC
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
|
@ -0,0 +1,10 @@
|
||||||
|
:mod:`DogeScramble` --- A word scramble game with rewards
|
||||||
|
=========================================================
|
||||||
|
|
||||||
|
This module provides a word scrambling game that rewards winners with small
|
||||||
|
amounts of Dogecoin
|
||||||
|
|
||||||
|
.. automodule:: modules.DogeScramble
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
|
@ -0,0 +1,9 @@
|
||||||
|
:mod:`DogeWallet` --- A Dogecoin wallet
|
||||||
|
=======================================
|
||||||
|
|
||||||
|
This module provides a dogecoin wallet hosted on the IRC bot's server
|
||||||
|
|
||||||
|
.. automodule:: modules.DogeWallet
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
|
@ -0,0 +1,9 @@
|
||||||
|
:mod:`DuckHunt` --- Duckhunt game
|
||||||
|
=================================
|
||||||
|
|
||||||
|
An animal hunting IRC game
|
||||||
|
|
||||||
|
.. automodule:: modules.DuckHunt
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
|
@ -0,0 +1,9 @@
|
||||||
|
:mod:`GameBase` --- IRC game codebase
|
||||||
|
=====================================
|
||||||
|
|
||||||
|
A codebase for making IRC games
|
||||||
|
|
||||||
|
.. automodule:: modules.GameBase
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
|
@ -0,0 +1,9 @@
|
||||||
|
:mod:`MySQL` --- MySQL service
|
||||||
|
==============================
|
||||||
|
|
||||||
|
Module providing a mysql type service
|
||||||
|
|
||||||
|
.. automodule:: modules.MySQL
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
|
@ -0,0 +1,9 @@
|
||||||
|
:mod:`NickUser` --- A module to cause an error
|
||||||
|
==============================================
|
||||||
|
|
||||||
|
A module providing a simple login/logout account service
|
||||||
|
|
||||||
|
.. automodule:: modules.NickUser
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
|
@ -0,0 +1,9 @@
|
||||||
|
:mod:`PingResponder` --- Service ping responder
|
||||||
|
===============================================
|
||||||
|
|
||||||
|
Module to repsond to irc server PING requests
|
||||||
|
|
||||||
|
.. automodule:: modules.PingResponder
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
|
@ -0,0 +1,9 @@
|
||||||
|
:mod:`Seen` --- !seen <username>
|
||||||
|
================================
|
||||||
|
|
||||||
|
Provides !seen <username>
|
||||||
|
|
||||||
|
.. automodule:: modules.Seen
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
|
@ -1,4 +1,12 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
"""
|
||||||
|
.. module:: AttributeStorage
|
||||||
|
:synopsis: An item key->value storage engine based on mysql
|
||||||
|
|
||||||
|
.. moduleauthor:: Dave Pedu <dave@davepedu.com>
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
from modulebase import ModuleBase,ModuleHook
|
from modulebase import ModuleBase,ModuleHook
|
||||||
|
|
||||||
class AttributeStorage(ModuleBase):
|
class AttributeStorage(ModuleBase):
|
||||||
|
@ -44,12 +52,17 @@ class AttributeStorage(ModuleBase):
|
||||||
c.close()
|
c.close()
|
||||||
|
|
||||||
# self.getItem('xMopxShell', 'name')
|
# self.getItem('xMopxShell', 'name')
|
||||||
# self.getAttribute('xMopxShell', 'name')
|
# self.getKey('xMopxShell', 'name')
|
||||||
# self.setAttribute('xMopxShell', 'name', 'dave')
|
# self.setKey('xMopxShell', 'name', 'dave')
|
||||||
|
|
||||||
# SELECT `i`.`id`, `i`.`item`, `a`.`attribute`, `v`.`value` FROM `items` `i` INNER JOIN `values` `v` on `v`.`itemid`=`i`.`id` INNER JOIN `attribute` `a` on `a`.`id`=`v`.`attributeid` ORDER BY `i`.`id` ASC, `a`.`id` ASC LIMIT 1000 ;
|
# SELECT `i`.`id`, `i`.`item`, `a`.`attribute`, `v`.`value` FROM `items` `i` INNER JOIN `values` `v` on `v`.`itemid`=`i`.`id` INNER JOIN `attribute` `a` on `a`.`id`=`v`.`attributeid` ORDER BY `i`.`id` ASC, `a`.`id` ASC LIMIT 1000 ;
|
||||||
|
|
||||||
def getItem(self, name):
|
def getItem(self, name):
|
||||||
|
"""Get all values for a item
|
||||||
|
|
||||||
|
:param name: the item
|
||||||
|
:type name: str
|
||||||
|
:returns: dict -- the item's values expressed as a dict"""
|
||||||
c = self.db.connection.query("""SELECT
|
c = self.db.connection.query("""SELECT
|
||||||
`i`.`id`,
|
`i`.`id`,
|
||||||
`i`.`item`,
|
`i`.`item`,
|
||||||
|
@ -78,7 +91,14 @@ class AttributeStorage(ModuleBase):
|
||||||
return {}
|
return {}
|
||||||
return item
|
return item
|
||||||
|
|
||||||
def getAttribute(self, item, attribute):
|
def getKey(self, item, key):
|
||||||
|
"""Get the value of an key on an item
|
||||||
|
|
||||||
|
:param item: the item to fetch a key from
|
||||||
|
:type item: str
|
||||||
|
:param key: they key who's value to return
|
||||||
|
:type key: str
|
||||||
|
:returns: str -- the item from the database or **None**"""
|
||||||
c = self.db.connection.query("""SELECT
|
c = self.db.connection.query("""SELECT
|
||||||
`i`.`id`,
|
`i`.`id`,
|
||||||
`i`.`item`,
|
`i`.`item`,
|
||||||
|
@ -95,7 +115,7 @@ class AttributeStorage(ModuleBase):
|
||||||
`i`.`item`=%s
|
`i`.`item`=%s
|
||||||
AND
|
AND
|
||||||
`a`.`attribute`=%s;""",
|
`a`.`attribute`=%s;""",
|
||||||
(item,attribute)
|
(item,key)
|
||||||
)
|
)
|
||||||
row = c.fetchone()
|
row = c.fetchone()
|
||||||
c.close()
|
c.close()
|
||||||
|
@ -103,9 +123,17 @@ class AttributeStorage(ModuleBase):
|
||||||
return None
|
return None
|
||||||
return row["value"]
|
return row["value"]
|
||||||
|
|
||||||
def setAttribute(self, item, attribute, value):
|
def setKey(self, item, key, value):
|
||||||
|
"""Set the key on an item
|
||||||
|
|
||||||
|
:param item: the item name to set the key on
|
||||||
|
:type item: str
|
||||||
|
:param key: the key to set
|
||||||
|
:type key: tuple
|
||||||
|
:param value: the value to set
|
||||||
|
:type value: str"""
|
||||||
item = item.lower()
|
item = item.lower()
|
||||||
attribute = attribute.lower()
|
attribute = key.lower()
|
||||||
|
|
||||||
# Check attribute exists
|
# Check attribute exists
|
||||||
c = self.db.connection.query("SELECT `id` FROM `attribute` WHERE `attribute`=%s;", (attribute))
|
c = self.db.connection.query("SELECT `id` FROM `attribute` WHERE `attribute`=%s;", (attribute))
|
||||||
|
|
|
@ -1,4 +1,12 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
"""
|
||||||
|
.. module:: Error
|
||||||
|
:synopsis: Module to provide a multi-type cryptocurrency wallet
|
||||||
|
|
||||||
|
.. moduleauthor:: Dave Pedu <dave@davepedu.com>
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
from modulebase import ModuleBase,ModuleHook
|
from modulebase import ModuleBase,ModuleHook
|
||||||
import time
|
import time
|
||||||
import hashlib
|
import hashlib
|
||||||
|
@ -44,7 +52,7 @@ class CryptoWallet(ModuleBase):
|
||||||
self.checkUserHasWallet(prefix.nick, cmd.args[0])
|
self.checkUserHasWallet(prefix.nick, cmd.args[0])
|
||||||
|
|
||||||
# Set their address
|
# Set their address
|
||||||
attr.setAttribute(prefix.nick, "cryptowallet-%s-address"%cmd.args[0].lower(), cmd.args[1])
|
attr.setKey(prefix.nick, "cryptowallet-%s-address"%cmd.args[0].lower(), cmd.args[1])
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".setaddr: Your address has been saved as: %s. Please verify that this is correct or your coins could be lost." % (cmd.args[1]))
|
self.bot.act_PRIVMSG(prefix.nick, ".setaddr: Your address has been saved as: %s. Please verify that this is correct or your coins could be lost." % (cmd.args[1]))
|
||||||
|
|
||||||
def handle_getbal(self, args, prefix, trailing, cmd):
|
def handle_getbal(self, args, prefix, trailing, cmd):
|
||||||
|
@ -69,7 +77,7 @@ class CryptoWallet(ModuleBase):
|
||||||
self.checkUserHasWallet(prefix.nick, cmd.args[0])
|
self.checkUserHasWallet(prefix.nick, cmd.args[0])
|
||||||
|
|
||||||
# fetch RPC and tell them the balance
|
# fetch RPC and tell them the balance
|
||||||
walletname = attr.getAttribute(prefix.nick, "cryptowallet-account-%s"%cmd.args[0].lower())
|
walletname = attr.getKey(prefix.nick, "cryptowallet-account-%s"%cmd.args[0].lower())
|
||||||
amount = 0.0
|
amount = 0.0
|
||||||
if walletname:
|
if walletname:
|
||||||
client = rpc.getRpc(cmd.args[0].lower())
|
client = rpc.getRpc(cmd.args[0].lower())
|
||||||
|
@ -98,13 +106,13 @@ class CryptoWallet(ModuleBase):
|
||||||
self.checkUserHasWallet(prefix.nick, cmd.args[0])
|
self.checkUserHasWallet(prefix.nick, cmd.args[0])
|
||||||
|
|
||||||
# check that they have a withdraw addr
|
# check that they have a withdraw addr
|
||||||
withdrawaddr = attr.getAttribute(prefix.nick, "cryptowallet-%s-address"%cmd.args[0].lower())
|
withdrawaddr = attr.getKey(prefix.nick, "cryptowallet-%s-address"%cmd.args[0].lower())
|
||||||
if withdrawaddr == None:
|
if withdrawaddr == None:
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".withdraw: You need to set a withdraw address before withdrawing. Try .setaddr")
|
self.bot.act_PRIVMSG(prefix.nick, ".withdraw: You need to set a withdraw address before withdrawing. Try .setaddr")
|
||||||
return
|
return
|
||||||
|
|
||||||
# fetch RPC and check balance
|
# fetch RPC and check balance
|
||||||
walletname = attr.getAttribute(prefix.nick, "cryptowallet-account-%s"%cmd.args[0].lower())
|
walletname = attr.getKey(prefix.nick, "cryptowallet-account-%s"%cmd.args[0].lower())
|
||||||
balance = 0.0
|
balance = 0.0
|
||||||
|
|
||||||
client = rpc.getRpc(cmd.args[0].lower())
|
client = rpc.getRpc(cmd.args[0].lower())
|
||||||
|
@ -154,7 +162,7 @@ class CryptoWallet(ModuleBase):
|
||||||
# Just make sure they have a wallet
|
# Just make sure they have a wallet
|
||||||
self.checkUserHasWallet(prefix.nick, cmd.args[0])
|
self.checkUserHasWallet(prefix.nick, cmd.args[0])
|
||||||
|
|
||||||
walletaddr = attr.getAttribute(prefix.nick, "cryptowallet-depoaddr-%s"%cmd.args[0].lower())
|
walletaddr = attr.getKey(prefix.nick, "cryptowallet-depoaddr-%s"%cmd.args[0].lower())
|
||||||
self.bot.act_PRIVMSG(prefix.nick, "Your %s deposit address is: %s" % (cmd.args[0].upper(), walletaddr))
|
self.bot.act_PRIVMSG(prefix.nick, "Your %s deposit address is: %s" % (cmd.args[0].upper(), walletaddr))
|
||||||
|
|
||||||
def handle_curinfo(self, args, prefix, trailing, cmd):
|
def handle_curinfo(self, args, prefix, trailing, cmd):
|
||||||
|
@ -178,18 +186,18 @@ class CryptoWallet(ModuleBase):
|
||||||
# Ensure the user has a wallet in the client
|
# Ensure the user has a wallet in the client
|
||||||
attr,login,rpc = self.getMods()
|
attr,login,rpc = self.getMods()
|
||||||
currency = currency.lower()
|
currency = currency.lower()
|
||||||
if attr.getAttribute(username, "cryptowallet-account-%s"%currency)==None:
|
if attr.getKey(username, "cryptowallet-account-%s"%currency)==None:
|
||||||
randName = self.md5(str(time.time()))[0:16]
|
randName = self.md5(str(time.time()))[0:16]
|
||||||
attr.setAttribute(username, "cryptowallet-account-%s"%currency, randName)
|
attr.setKey(username, "cryptowallet-account-%s"%currency, randName)
|
||||||
# Generate a deposit addr to nudge the wallet
|
# Generate a deposit addr to nudge the wallet
|
||||||
wallet = rpc.getRpc(currency.lower())
|
wallet = rpc.getRpc(currency.lower())
|
||||||
address = wallet.getAcctAddr(randName)
|
address = wallet.getAcctAddr(randName)
|
||||||
attr.setAttribute(username, "cryptowallet-depoaddr-%s"%currency, address)
|
attr.setKey(username, "cryptowallet-depoaddr-%s"%currency, address)
|
||||||
elif attr.getAttribute(username, "cryptowallet-depoaddr-%s"%currency)==None:
|
elif attr.getKey(username, "cryptowallet-depoaddr-%s"%currency)==None:
|
||||||
walletName = attr.getAttribute(username, "cryptowallet-account-%s"%currency)
|
walletName = attr.getKey(username, "cryptowallet-account-%s"%currency)
|
||||||
wallet = rpc.getRpc(currency.lower())
|
wallet = rpc.getRpc(currency.lower())
|
||||||
address = wallet.getAcctAddr(walletName)
|
address = wallet.getAcctAddr(walletName)
|
||||||
attr.setAttribute(username, "cryptowallet-depoaddr-%s"%currency, address)
|
attr.setKey(username, "cryptowallet-depoaddr-%s"%currency, address)
|
||||||
|
|
||||||
|
|
||||||
def handlePm(self, args, prefix, trailing):
|
def handlePm(self, args, prefix, trailing):
|
||||||
|
|
|
@ -1,4 +1,12 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
"""
|
||||||
|
.. module:: CryptoWalletRPC
|
||||||
|
:synopsis: Module capable of operating bitcoind-style RPC. Provided as a service.
|
||||||
|
|
||||||
|
.. moduleauthor:: Dave Pedu <dave@davepedu.com>
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
from modulebase import ModuleBase,ModuleHook
|
from modulebase import ModuleBase,ModuleHook
|
||||||
from bitcoinrpc.authproxy import AuthServiceProxy
|
from bitcoinrpc.authproxy import AuthServiceProxy
|
||||||
from math import floor
|
from math import floor
|
||||||
|
|
|
@ -1,4 +1,12 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
"""
|
||||||
|
.. module:: DogeDice
|
||||||
|
:synopsis: Module to provide a game for gambling Dogecoin
|
||||||
|
|
||||||
|
.. moduleauthor:: Dave Pedu <dave@davepedu.com>
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
from modulebase import ModuleBase,ModuleHook
|
from modulebase import ModuleBase,ModuleHook
|
||||||
import random
|
import random
|
||||||
import yaml
|
import yaml
|
||||||
|
@ -23,7 +31,7 @@ class DogeDice(ModuleBase):
|
||||||
def gotMsg(self, args, prefix, trailing):
|
def gotMsg(self, args, prefix, trailing):
|
||||||
prefixObj = self.bot.decodePrefix(prefix)
|
prefixObj = self.bot.decodePrefix(prefix)
|
||||||
# Ignore messages from users not logged in
|
# Ignore messages from users not logged in
|
||||||
loggedinfrom = self.attr.getAttribute(prefixObj.nick, "loggedinfrom")
|
loggedinfrom = self.attr.getKey(prefixObj.nick, "loggedinfrom")
|
||||||
if loggedinfrom==None:
|
if loggedinfrom==None:
|
||||||
# Send them a hint?
|
# Send them a hint?
|
||||||
return
|
return
|
||||||
|
@ -104,7 +112,7 @@ class gameObj:
|
||||||
if cmd:
|
if cmd:
|
||||||
if len(self.players)-1 < self.maxPlayers:
|
if len(self.players)-1 < self.maxPlayers:
|
||||||
if self.getPlayer(prefix.nick)==None:
|
if self.getPlayer(prefix.nick)==None:
|
||||||
userWallet = self.master.attr.getAttribute(prefix.nick, "dogeaccountname")
|
userWallet = self.master.attr.getKey(prefix.nick, "dogeaccountname")
|
||||||
if userWallet == None:
|
if userWallet == None:
|
||||||
self.master.bot.act_PRIVMSG(self.channel, "%s: You don't have enough DOGE!" % (prefix.nick))
|
self.master.bot.act_PRIVMSG(self.channel, "%s: You don't have enough DOGE!" % (prefix.nick))
|
||||||
return
|
return
|
||||||
|
@ -194,7 +202,7 @@ class gameObj:
|
||||||
elif self.step == 4:
|
elif self.step == 4:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
#senderIsOp = self.master.attr.getAttribute(prefix.nick, "op")=="yes"
|
#senderIsOp = self.master.attr.getKey(prefix.nick, "op")=="yes"
|
||||||
def clearTimer(self, timer):
|
def clearTimer(self, timer):
|
||||||
if timer:
|
if timer:
|
||||||
timer.cancel()
|
timer.cancel()
|
||||||
|
|
|
@ -1,4 +1,12 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
"""
|
||||||
|
.. module:: DogeRPC
|
||||||
|
:synopsis: Provides a service for interacting with dogecoind.
|
||||||
|
|
||||||
|
.. moduleauthor:: Dave Pedu <dave@davepedu.com>
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
from modulebase import ModuleBase,ModuleHook
|
from modulebase import ModuleBase,ModuleHook
|
||||||
from bitcoinrpc.authproxy import AuthServiceProxy
|
from bitcoinrpc.authproxy import AuthServiceProxy
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,12 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
"""
|
||||||
|
.. module:: DogeScramble
|
||||||
|
:synopsis: This module provides a word scrambling game that rewards winners with small amounts of Dogecoin
|
||||||
|
|
||||||
|
.. moduleauthor:: Dave Pedu <dave@davepedu.com>
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
from modulebase import ModuleBase,ModuleHook
|
from modulebase import ModuleBase,ModuleHook
|
||||||
import random
|
import random
|
||||||
import yaml
|
import yaml
|
||||||
|
@ -32,7 +40,7 @@ class DogeScramble(ModuleBase):
|
||||||
if channel[0] == "#":
|
if channel[0] == "#":
|
||||||
# Ignore messages from users without a dogewallet password
|
# Ignore messages from users without a dogewallet password
|
||||||
prefixObj = self.bot.decodePrefix(prefix)
|
prefixObj = self.bot.decodePrefix(prefix)
|
||||||
if self.attr.getAttribute(prefixObj.nick, "password")==None:
|
if self.attr.getKey(prefixObj.nick, "password")==None:
|
||||||
return
|
return
|
||||||
if not channel in self.games:
|
if not channel in self.games:
|
||||||
self.games[channel]=scrambleGame(self, channel)
|
self.games[channel]=scrambleGame(self, channel)
|
||||||
|
@ -98,7 +106,7 @@ class scrambleGame:
|
||||||
prefix = self.master.bot.decodePrefix(prefix)
|
prefix = self.master.bot.decodePrefix(prefix)
|
||||||
sender = prefix.nick
|
sender = prefix.nick
|
||||||
|
|
||||||
senderIsOp = self.master.attr.getAttribute(prefix.nick, "op")=="yes"
|
senderIsOp = self.master.attr.getKey(prefix.nick, "op")=="yes"
|
||||||
|
|
||||||
cmd = self.master.bot.messageHasCommand(".scramble", trailing)
|
cmd = self.master.bot.messageHasCommand(".scramble", trailing)
|
||||||
if cmd and not self.running:
|
if cmd and not self.running:
|
||||||
|
@ -114,8 +122,8 @@ class scrambleGame:
|
||||||
|
|
||||||
if self.currentWord and trailing.strip().lower() == self.currentWord:
|
if self.currentWord and trailing.strip().lower() == self.currentWord:
|
||||||
# Get winner withdraw address
|
# Get winner withdraw address
|
||||||
useraddr = self.master.attr.getAttribute(prefix.nick, "dogeaddr")
|
useraddr = self.master.attr.getKey(prefix.nick, "dogeaddr")
|
||||||
userwallet = self.master.attr.getAttribute(prefix.nick, "dogeaccountname")
|
userwallet = self.master.attr.getKey(prefix.nick, "dogeaccountname")
|
||||||
|
|
||||||
self.master.bot.act_PRIVMSG(self.channel, "%s got the word - %s!" % (sender, self.currentWord))
|
self.master.bot.act_PRIVMSG(self.channel, "%s got the word - %s!" % (sender, self.currentWord))
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,12 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
"""
|
||||||
|
.. module:: DogeWallet
|
||||||
|
:synopsis: Module to provide a Dogecoin wallet
|
||||||
|
|
||||||
|
.. moduleauthor:: Dave Pedu <dave@davepedu.com>
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
from modulebase import ModuleBase,ModuleHook
|
from modulebase import ModuleBase,ModuleHook
|
||||||
import time
|
import time
|
||||||
import hashlib
|
import hashlib
|
||||||
|
@ -27,14 +35,14 @@ class DogeWallet(ModuleBase):
|
||||||
if len(cmd.args)==0:
|
if len(cmd.args)==0:
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".setpass: usage: \".setpass newpass\" or \".setpass oldpass newpass\"")
|
self.bot.act_PRIVMSG(prefix.nick, ".setpass: usage: \".setpass newpass\" or \".setpass oldpass newpass\"")
|
||||||
else:
|
else:
|
||||||
oldpass = self.attr.getAttribute(prefix.nick, "password")
|
oldpass = self.attr.getKey(prefix.nick, "password")
|
||||||
if oldpass == None:
|
if oldpass == None:
|
||||||
self.attr.setAttribute(prefix.nick, "password", cmd.args[0])
|
self.attr.setKey(prefix.nick, "password", cmd.args[0])
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".setpass: Your password has been set to \"%s\"." % cmd.args[0])
|
self.bot.act_PRIVMSG(prefix.nick, ".setpass: Your password has been set to \"%s\"." % cmd.args[0])
|
||||||
else:
|
else:
|
||||||
if len(cmd.args)==2:
|
if len(cmd.args)==2:
|
||||||
if cmd.args[0] == oldpass:
|
if cmd.args[0] == oldpass:
|
||||||
self.attr.setAttribute(prefix.nick, "password", cmd.args[1])
|
self.attr.setKey(prefix.nick, "password", cmd.args[1])
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".setpass: Your password has been set to \"%s\"." % cmd.args[1])
|
self.bot.act_PRIVMSG(prefix.nick, ".setpass: Your password has been set to \"%s\"." % cmd.args[1])
|
||||||
else:
|
else:
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".setpass: Old password incorrect.")
|
self.bot.act_PRIVMSG(prefix.nick, ".setpass: Old password incorrect.")
|
||||||
|
@ -42,18 +50,18 @@ class DogeWallet(ModuleBase):
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".setpass: You must provide the old password when setting a new one.")
|
self.bot.act_PRIVMSG(prefix.nick, ".setpass: You must provide the old password when setting a new one.")
|
||||||
cmd = self.bot.messageHasCommand(".setdogeaddr", trailing)
|
cmd = self.bot.messageHasCommand(".setdogeaddr", trailing)
|
||||||
if cmd:
|
if cmd:
|
||||||
userpw = self.attr.getAttribute(prefix.nick, "password")
|
userpw = self.attr.getKey(prefix.nick, "password")
|
||||||
if userpw==None:
|
if userpw==None:
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".setdogeaddr: You must first set a password with .setpass")
|
self.bot.act_PRIVMSG(prefix.nick, ".setdogeaddr: You must first set a password with .setpass")
|
||||||
else:
|
else:
|
||||||
if len(cmd.args)==2:
|
if len(cmd.args)==2:
|
||||||
if userpw == cmd.args[0]:
|
if userpw == cmd.args[0]:
|
||||||
self.attr.setAttribute(prefix.nick, "dogeaddr", cmd.args[1])
|
self.attr.setKey(prefix.nick, "dogeaddr", cmd.args[1])
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".setdogeaddr: Your doge address has been set to \"%s\"." % cmd.args[1])
|
self.bot.act_PRIVMSG(prefix.nick, ".setdogeaddr: Your doge address has been set to \"%s\"." % cmd.args[1])
|
||||||
# if they don't have a wallet name, we'll make one now
|
# if they don't have a wallet name, we'll make one now
|
||||||
if self.attr.getAttribute(prefix.nick, "dogeaccountname")==None:
|
if self.attr.getKey(prefix.nick, "dogeaccountname")==None:
|
||||||
randName = self.md5(str(time.time()))[0:10]
|
randName = self.md5(str(time.time()))[0:10]
|
||||||
self.attr.setAttribute(prefix.nick, "dogeaccountname", randName)
|
self.attr.setKey(prefix.nick, "dogeaccountname", randName)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".setdogeaddr: incorrect password.")
|
self.bot.act_PRIVMSG(prefix.nick, ".setdogeaddr: incorrect password.")
|
||||||
|
@ -62,14 +70,14 @@ class DogeWallet(ModuleBase):
|
||||||
|
|
||||||
cmd = self.bot.messageHasCommand(".getdogebal", trailing)
|
cmd = self.bot.messageHasCommand(".getdogebal", trailing)
|
||||||
if cmd:
|
if cmd:
|
||||||
userpw = self.attr.getAttribute(prefix.nick, "password")
|
userpw = self.attr.getKey(prefix.nick, "password")
|
||||||
if userpw==None:
|
if userpw==None:
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".getdogebal: You must first set a password with .setpass")
|
self.bot.act_PRIVMSG(prefix.nick, ".getdogebal: You must first set a password with .setpass")
|
||||||
else:
|
else:
|
||||||
if len(cmd.args)==1:
|
if len(cmd.args)==1:
|
||||||
if userpw == cmd.args[0]:
|
if userpw == cmd.args[0]:
|
||||||
#################
|
#################
|
||||||
walletname = self.attr.getAttribute(prefix.nick, "dogeaccountname")
|
walletname = self.attr.getKey(prefix.nick, "dogeaccountname")
|
||||||
amount = 0.0
|
amount = 0.0
|
||||||
if walletname:
|
if walletname:
|
||||||
amount = self.doge.getBal(walletname)
|
amount = self.doge.getBal(walletname)
|
||||||
|
@ -84,8 +92,8 @@ class DogeWallet(ModuleBase):
|
||||||
|
|
||||||
cmd = self.bot.messageHasCommand(".withdrawdoge", trailing)
|
cmd = self.bot.messageHasCommand(".withdrawdoge", trailing)
|
||||||
if cmd:
|
if cmd:
|
||||||
userpw = self.attr.getAttribute(prefix.nick, "password")
|
userpw = self.attr.getKey(prefix.nick, "password")
|
||||||
useraddr = self.attr.getAttribute(prefix.nick, "dogeaddr")
|
useraddr = self.attr.getKey(prefix.nick, "dogeaddr")
|
||||||
if userpw==None:
|
if userpw==None:
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".withdrawdoge: You must first set a password with .setpass")
|
self.bot.act_PRIVMSG(prefix.nick, ".withdrawdoge: You must first set a password with .setpass")
|
||||||
elif useraddr==None:
|
elif useraddr==None:
|
||||||
|
@ -94,7 +102,7 @@ class DogeWallet(ModuleBase):
|
||||||
if len(cmd.args)==2:
|
if len(cmd.args)==2:
|
||||||
if userpw == cmd.args[0]:
|
if userpw == cmd.args[0]:
|
||||||
#################
|
#################
|
||||||
walletname = self.attr.getAttribute(prefix.nick, "dogeaccountname")
|
walletname = self.attr.getKey(prefix.nick, "dogeaccountname")
|
||||||
walletbal = self.doge.getBal(walletname)
|
walletbal = self.doge.getBal(walletname)
|
||||||
|
|
||||||
desiredAmount = float(cmd.args[1])
|
desiredAmount = float(cmd.args[1])
|
||||||
|
@ -115,14 +123,14 @@ class DogeWallet(ModuleBase):
|
||||||
|
|
||||||
cmd = self.bot.messageHasCommand(".getdepositaddr", trailing)
|
cmd = self.bot.messageHasCommand(".getdepositaddr", trailing)
|
||||||
if cmd:
|
if cmd:
|
||||||
userpw = self.attr.getAttribute(prefix.nick, "password")
|
userpw = self.attr.getKey(prefix.nick, "password")
|
||||||
if userpw==None:
|
if userpw==None:
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".getdepositaddr: You must first set a password with .setpass")
|
self.bot.act_PRIVMSG(prefix.nick, ".getdepositaddr: You must first set a password with .setpass")
|
||||||
else:
|
else:
|
||||||
if len(cmd.args)==1:
|
if len(cmd.args)==1:
|
||||||
if userpw == cmd.args[0]:
|
if userpw == cmd.args[0]:
|
||||||
#################
|
#################
|
||||||
walletname = self.attr.getAttribute(prefix.nick, "dogeaccountname")
|
walletname = self.attr.getKey(prefix.nick, "dogeaccountname")
|
||||||
addr = self.doge.getAcctAddr(walletname)
|
addr = self.doge.getAcctAddr(walletname)
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".getdepositaddr: Your deposit address is: %s" % addr)
|
self.bot.act_PRIVMSG(prefix.nick, ".getdepositaddr: Your deposit address is: %s" % addr)
|
||||||
#################
|
#################
|
||||||
|
@ -135,14 +143,14 @@ class DogeWallet(ModuleBase):
|
||||||
|
|
||||||
cmd = self.bot.messageHasCommand(".login", trailing)
|
cmd = self.bot.messageHasCommand(".login", trailing)
|
||||||
if cmd:
|
if cmd:
|
||||||
userpw = self.attr.getAttribute(prefix.nick, "password")
|
userpw = self.attr.getKey(prefix.nick, "password")
|
||||||
if userpw==None:
|
if userpw==None:
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".login: You must first set a password with .setpass")
|
self.bot.act_PRIVMSG(prefix.nick, ".login: You must first set a password with .setpass")
|
||||||
else:
|
else:
|
||||||
if len(cmd.args)==1:
|
if len(cmd.args)==1:
|
||||||
if userpw == cmd.args[0]:
|
if userpw == cmd.args[0]:
|
||||||
#################
|
#################
|
||||||
self.attr.setAttribute(prefix.nick, "loggedinfrom", prefix.hostname)
|
self.attr.setKey(prefix.nick, "loggedinfrom", prefix.hostname)
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".login: You have been logged in from: %s" % prefix.hostname)
|
self.bot.act_PRIVMSG(prefix.nick, ".login: You have been logged in from: %s" % prefix.hostname)
|
||||||
#################
|
#################
|
||||||
else:
|
else:
|
||||||
|
@ -151,11 +159,11 @@ class DogeWallet(ModuleBase):
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".login: usage: \".login password\"")
|
self.bot.act_PRIVMSG(prefix.nick, ".login: usage: \".login password\"")
|
||||||
cmd = self.bot.messageHasCommand(".logout", trailing)
|
cmd = self.bot.messageHasCommand(".logout", trailing)
|
||||||
if cmd:
|
if cmd:
|
||||||
loggedin = self.attr.getAttribute(prefix.nick, "loggedinfrom")
|
loggedin = self.attr.getKey(prefix.nick, "loggedinfrom")
|
||||||
if loggedin == None:
|
if loggedin == None:
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".logout: You must first be logged in")
|
self.bot.act_PRIVMSG(prefix.nick, ".logout: You must first be logged in")
|
||||||
else:
|
else:
|
||||||
self.attr.setAttribute(prefix.nick, "loggedinfrom", None)
|
self.attr.setKey(prefix.nick, "loggedinfrom", None)
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".logout: You have been logged out.")
|
self.bot.act_PRIVMSG(prefix.nick, ".logout: You have been logged out.")
|
||||||
|
|
||||||
def md5(self, data):
|
def md5(self, data):
|
||||||
|
|
|
@ -1,4 +1,12 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
"""
|
||||||
|
.. module:: DuckHunt
|
||||||
|
:synopsis: An animal hunting IRC game
|
||||||
|
|
||||||
|
.. moduleauthor:: Dave Pedu <dave@davepedu.com>
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
from modulebase import ModuleBase,ModuleHook
|
from modulebase import ModuleBase,ModuleHook
|
||||||
import time
|
import time
|
||||||
import yaml
|
import yaml
|
||||||
|
|
|
@ -1,4 +1,12 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
"""
|
||||||
|
.. module:: GameBase
|
||||||
|
:synopsis: A codebase for making IRC games
|
||||||
|
|
||||||
|
.. moduleauthor:: Dave Pedu <dave@davepedu.com>
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
from modulebase import ModuleBase,ModuleHook
|
from modulebase import ModuleBase,ModuleHook
|
||||||
import random
|
import random
|
||||||
import yaml
|
import yaml
|
||||||
|
@ -21,7 +29,7 @@ class GameBase(ModuleBase):
|
||||||
def gotMsg(self, args, prefix, trailing):
|
def gotMsg(self, args, prefix, trailing):
|
||||||
prefixObj = self.bot.decodePrefix(prefix)
|
prefixObj = self.bot.decodePrefix(prefix)
|
||||||
# Ignore messages from users not logged in
|
# Ignore messages from users not logged in
|
||||||
if self.attr.getAttribute(prefixObj.nick, "loggedinfrom")==None:
|
if self.attr.getKey(prefixObj.nick, "loggedinfrom")==None:
|
||||||
# Send them a hint?
|
# Send them a hint?
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
@ -54,7 +62,7 @@ class gameObj:
|
||||||
prefix = self.master.bot.decodePrefix(prefix)
|
prefix = self.master.bot.decodePrefix(prefix)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
#senderIsOp = self.master.attr.getAttribute(prefix.nick, "op")=="yes"
|
#senderIsOp = self.master.attr.getKey(prefix.nick, "op")=="yes"
|
||||||
def gameover(self):
|
def gameover(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,12 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
"""
|
||||||
|
.. module:: MySQL
|
||||||
|
:synopsis: Module providing a mysql type service
|
||||||
|
|
||||||
|
.. moduleauthor:: Dave Pedu <dave@davepedu.com>
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
from modulebase import ModuleBase,ModuleHook
|
from modulebase import ModuleBase,ModuleHook
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -39,6 +47,13 @@ class Connection:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def query(self, queryText, args=()):
|
def query(self, queryText, args=()):
|
||||||
|
"""Execute a MySQL query and return the cursor
|
||||||
|
|
||||||
|
:param queryText: the mysql query as a string, using '%s' for token replacement
|
||||||
|
:type queryText: str
|
||||||
|
:param args: arguments to be escaped into the query
|
||||||
|
:type args: tuple
|
||||||
|
:returns: cursor -- the sql cursor"""
|
||||||
c = self.getCursor()
|
c = self.getCursor()
|
||||||
if len(args)==0:
|
if len(args)==0:
|
||||||
c.execute(queryText)
|
c.execute(queryText)
|
||||||
|
@ -57,6 +72,11 @@ class Connection:
|
||||||
return c
|
return c
|
||||||
|
|
||||||
def escape(self, s):
|
def escape(self, s):
|
||||||
|
"""Escape a string using the mysql server
|
||||||
|
|
||||||
|
:param s: the string to escape
|
||||||
|
:type s: str
|
||||||
|
:returns: str -- the escaped string"""
|
||||||
self.ensureConnected()
|
self.ensureConnected()
|
||||||
return self.connection.escape_string(s)
|
return self.connection.escape_string(s)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,12 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
"""
|
||||||
|
.. module:: NickUser
|
||||||
|
:synopsis: A module providing a simple login/logout account service
|
||||||
|
|
||||||
|
.. moduleauthor:: Dave Pedu <dave@davepedu.com>
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
from modulebase import ModuleBase,ModuleHook
|
from modulebase import ModuleBase,ModuleHook
|
||||||
import time
|
import time
|
||||||
import hashlib
|
import hashlib
|
||||||
|
@ -11,7 +19,7 @@ class NickUser(ModuleBase):
|
||||||
|
|
||||||
def check(self, nick, hostname):
|
def check(self, nick, hostname):
|
||||||
attr = self.bot.getBestModuleForService("attributes")
|
attr = self.bot.getBestModuleForService("attributes")
|
||||||
loggedin = attr.getAttribute(nick, "loggedinfrom")
|
loggedin = attr.getKey(nick, "loggedinfrom")
|
||||||
if hostname==loggedin:
|
if hostname==loggedin:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
@ -36,14 +44,14 @@ class NickUser(ModuleBase):
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".setpass: usage: \".setpass newpass\" or \".setpass oldpass newpass\"")
|
self.bot.act_PRIVMSG(prefix.nick, ".setpass: usage: \".setpass newpass\" or \".setpass oldpass newpass\"")
|
||||||
else:
|
else:
|
||||||
attr = self.bot.getBestModuleForService("attributes")
|
attr = self.bot.getBestModuleForService("attributes")
|
||||||
oldpass = attr.getAttribute(prefix.nick, "password")
|
oldpass = attr.getKey(prefix.nick, "password")
|
||||||
if oldpass == None:
|
if oldpass == None:
|
||||||
attr.setAttribute(prefix.nick, "password", cmd.args[0])
|
attr.setKey(prefix.nick, "password", cmd.args[0])
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".setpass: Your password has been set to \"%s\"." % cmd.args[0])
|
self.bot.act_PRIVMSG(prefix.nick, ".setpass: Your password has been set to \"%s\"." % cmd.args[0])
|
||||||
else:
|
else:
|
||||||
if len(cmd.args)==2:
|
if len(cmd.args)==2:
|
||||||
if cmd.args[0] == oldpass:
|
if cmd.args[0] == oldpass:
|
||||||
attr.setAttribute(prefix.nick, "password", cmd.args[1])
|
attr.setKey(prefix.nick, "password", cmd.args[1])
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".setpass: Your password has been set to \"%s\"." % cmd.args[1])
|
self.bot.act_PRIVMSG(prefix.nick, ".setpass: Your password has been set to \"%s\"." % cmd.args[1])
|
||||||
else:
|
else:
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".setpass: Old password incorrect.")
|
self.bot.act_PRIVMSG(prefix.nick, ".setpass: Old password incorrect.")
|
||||||
|
@ -53,14 +61,14 @@ class NickUser(ModuleBase):
|
||||||
cmd = self.bot.messageHasCommand(".login", trailing)
|
cmd = self.bot.messageHasCommand(".login", trailing)
|
||||||
if cmd:
|
if cmd:
|
||||||
attr = self.bot.getBestModuleForService("attributes")
|
attr = self.bot.getBestModuleForService("attributes")
|
||||||
userpw = attr.getAttribute(prefix.nick, "password")
|
userpw = attr.getKey(prefix.nick, "password")
|
||||||
if userpw==None:
|
if userpw==None:
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".login: You must first set a password with .setpass")
|
self.bot.act_PRIVMSG(prefix.nick, ".login: You must first set a password with .setpass")
|
||||||
else:
|
else:
|
||||||
if len(cmd.args)==1:
|
if len(cmd.args)==1:
|
||||||
if userpw == cmd.args[0]:
|
if userpw == cmd.args[0]:
|
||||||
#################
|
#################
|
||||||
attr.setAttribute(prefix.nick, "loggedinfrom", prefix.hostname)
|
attr.setKey(prefix.nick, "loggedinfrom", prefix.hostname)
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".login: You have been logged in from: %s" % prefix.hostname)
|
self.bot.act_PRIVMSG(prefix.nick, ".login: You have been logged in from: %s" % prefix.hostname)
|
||||||
#################
|
#################
|
||||||
else:
|
else:
|
||||||
|
@ -70,11 +78,11 @@ class NickUser(ModuleBase):
|
||||||
cmd = self.bot.messageHasCommand(".logout", trailing)
|
cmd = self.bot.messageHasCommand(".logout", trailing)
|
||||||
if cmd:
|
if cmd:
|
||||||
attr = self.bot.getBestModuleForService("attributes")
|
attr = self.bot.getBestModuleForService("attributes")
|
||||||
loggedin = attr.getAttribute(prefix.nick, "loggedinfrom")
|
loggedin = attr.getKey(prefix.nick, "loggedinfrom")
|
||||||
if loggedin == None:
|
if loggedin == None:
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".logout: You must first be logged in")
|
self.bot.act_PRIVMSG(prefix.nick, ".logout: You must first be logged in")
|
||||||
else:
|
else:
|
||||||
attr.setAttribute(prefix.nick, "loggedinfrom", None)
|
attr.setKey(prefix.nick, "loggedinfrom", None)
|
||||||
self.bot.act_PRIVMSG(prefix.nick, ".logout: You have been logged out.")
|
self.bot.act_PRIVMSG(prefix.nick, ".logout: You have been logged out.")
|
||||||
|
|
||||||
def md5(self, data):
|
def md5(self, data):
|
||||||
|
|
|
@ -1,63 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
from modulebase import ModuleBase,ModuleHook
|
|
||||||
import re
|
|
||||||
from time import time
|
|
||||||
from urllib import request
|
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
from bs4.element import Tag as bs_type_tag
|
|
||||||
|
|
||||||
class NyanThread(ModuleBase):
|
|
||||||
def __init__(self, bot, moduleName):
|
|
||||||
ModuleBase.__init__(self, bot, moduleName);
|
|
||||||
self.hooks=[ModuleHook("PRIVMSG", self.check)]
|
|
||||||
self.lastrun = 0
|
|
||||||
self.pagepattern = re.compile(r'<a class="navPages" href="https:\/\/bitcointalk\.org\/index\.php\?topic=403335\.([0-9]+)">([0-9]+)</a>')
|
|
||||||
self.messagepattern = re.compile(r'<span style="color: RED;">([^<]+)</span>', flags=re.IGNORECASE)
|
|
||||||
self.linkmessage = re.compile(r'<a href="https:\/\/bitcointalk\.org\/index\.php\?topic=403335\.msg([0-9]+)#msg([0-9]+)">')
|
|
||||||
|
|
||||||
def check(self, args, prefix, trailing):
|
|
||||||
if not args[0][0]=="#":
|
|
||||||
return
|
|
||||||
cmd = self.bot.messageHasCommand(".story", trailing)
|
|
||||||
if cmd:
|
|
||||||
if time() - self.lastrun < 10:
|
|
||||||
return
|
|
||||||
|
|
||||||
self.log.info("Nyanthread: fetching story...")
|
|
||||||
prefixObj = self.bot.decodePrefix(prefix)
|
|
||||||
page = request.urlopen("https://bitcointalk.org/index.php?topic=403335").read()
|
|
||||||
pages = self.pagepattern.findall(page.decode("ISO-8859-1"))
|
|
||||||
lastpage = pages[-1]
|
|
||||||
lastpagelink = "https://bitcointalk.org/index.php?topic=403335.%s" % lastpage[0]
|
|
||||||
self.log.info("Nyanthread: last page is %s" % lastpagelink)
|
|
||||||
page = request.urlopen(lastpagelink).read()
|
|
||||||
|
|
||||||
bs = BeautifulSoup(page)
|
|
||||||
|
|
||||||
body = bs.find('div', id="bodyarea")
|
|
||||||
thread = body.find('form', id="quickModForm")
|
|
||||||
posttable = thread.find('table', class_="bordercolor")
|
|
||||||
|
|
||||||
postTrs = []
|
|
||||||
for item in posttable:
|
|
||||||
postTrs.append(item)
|
|
||||||
|
|
||||||
postTrs.reverse()
|
|
||||||
|
|
||||||
for item in postTrs:
|
|
||||||
if type(item) == bs_type_tag:
|
|
||||||
message = item.find('div', class_="post")
|
|
||||||
if message:
|
|
||||||
redContent = self.messagepattern.findall(message.decode_contents())
|
|
||||||
if len(redContent)>0:
|
|
||||||
linkmessage = self.linkmessage.findall(item.decode_contents())
|
|
||||||
lastpagelink = "https://bitcointalk.org/index.php?topic=403335.msg%s#msg%s"%(linkmessage[0][0],linkmessage[0][0])
|
|
||||||
if len(linkmessage)>75:
|
|
||||||
continue
|
|
||||||
self.bot.act_PRIVMSG(args[0], "%s: %s - %s" % (prefixObj.nick, redContent[0], lastpagelink))
|
|
||||||
self.lastrun = time()
|
|
||||||
return
|
|
||||||
|
|
||||||
self.bot.act_PRIVMSG(args[0], "%s: failed to read thread :(" % (prefixObj.nick))
|
|
||||||
self.lastrun = time()
|
|
||||||
return
|
|
|
@ -1,4 +1,12 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
"""
|
||||||
|
.. module:: PingResponder
|
||||||
|
:synopsis: Module to repsond to irc server PING requests
|
||||||
|
|
||||||
|
.. moduleauthor:: Dave Pedu <dave@davepedu.com>
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
from modulebase import ModuleBase,ModuleHook
|
from modulebase import ModuleBase,ModuleHook
|
||||||
|
|
||||||
class PingResponder(ModuleBase):
|
class PingResponder(ModuleBase):
|
||||||
|
|
|
@ -1,4 +1,12 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
"""
|
||||||
|
.. module:: Seen
|
||||||
|
:synopsis: Provides !seen <username>
|
||||||
|
|
||||||
|
.. moduleauthor:: Dave Pedu <dave@davepedu.com>
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
from modulebase import ModuleBase,ModuleHook
|
from modulebase import ModuleBase,ModuleHook
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import time
|
import time
|
||||||
|
|
Loading…
Reference in New Issue