diff --git a/docs/.DS_Store b/docs/.DS_Store deleted file mode 100644 index 6997a9a..0000000 Binary files a/docs/.DS_Store and /dev/null differ diff --git a/docs/._.DS_Store b/docs/api/._.DS_Store similarity index 98% rename from docs/._.DS_Store rename to docs/api/._.DS_Store index 4363dec..40565d6 100644 Binary files a/docs/._.DS_Store and b/docs/api/._.DS_Store differ diff --git a/docs/api/modules/attributestorage.rst b/docs/api/modules/attributestorage.rst new file mode 100644 index 0000000..906ded8 --- /dev/null +++ b/docs/api/modules/attributestorage.rst @@ -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: diff --git a/docs/api/modules/cryptowallet.rst b/docs/api/modules/cryptowallet.rst new file mode 100644 index 0000000..504e2eb --- /dev/null +++ b/docs/api/modules/cryptowallet.rst @@ -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: diff --git a/docs/api/modules/cryptowalletrpc.rst b/docs/api/modules/cryptowalletrpc.rst new file mode 100644 index 0000000..bedad0a --- /dev/null +++ b/docs/api/modules/cryptowalletrpc.rst @@ -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: diff --git a/docs/api/modules/dogedice.rst b/docs/api/modules/dogedice.rst new file mode 100644 index 0000000..6dfeb01 --- /dev/null +++ b/docs/api/modules/dogedice.rst @@ -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: diff --git a/docs/api/modules/dogerpc.rst b/docs/api/modules/dogerpc.rst new file mode 100644 index 0000000..17555b8 --- /dev/null +++ b/docs/api/modules/dogerpc.rst @@ -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: diff --git a/docs/api/modules/dogescramble.rst b/docs/api/modules/dogescramble.rst new file mode 100644 index 0000000..3ceccbf --- /dev/null +++ b/docs/api/modules/dogescramble.rst @@ -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: diff --git a/docs/api/modules/dogewallet.rst b/docs/api/modules/dogewallet.rst new file mode 100644 index 0000000..a04e147 --- /dev/null +++ b/docs/api/modules/dogewallet.rst @@ -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: diff --git a/docs/api/modules/duckhunt.rst b/docs/api/modules/duckhunt.rst new file mode 100644 index 0000000..e559c07 --- /dev/null +++ b/docs/api/modules/duckhunt.rst @@ -0,0 +1,9 @@ +:mod:`DuckHunt` --- Duckhunt game +================================= + +An animal hunting IRC game + +.. automodule:: modules.DuckHunt + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/api/modules/gamebase.rst b/docs/api/modules/gamebase.rst new file mode 100644 index 0000000..89b6d40 --- /dev/null +++ b/docs/api/modules/gamebase.rst @@ -0,0 +1,9 @@ +:mod:`GameBase` --- IRC game codebase +===================================== + +A codebase for making IRC games + +.. automodule:: modules.GameBase + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/api/modules/mysql.rst b/docs/api/modules/mysql.rst new file mode 100644 index 0000000..638924f --- /dev/null +++ b/docs/api/modules/mysql.rst @@ -0,0 +1,9 @@ +:mod:`MySQL` --- MySQL service +============================== + +Module providing a mysql type service + +.. automodule:: modules.MySQL + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/api/modules/nickuser.rst b/docs/api/modules/nickuser.rst new file mode 100644 index 0000000..1c01c6e --- /dev/null +++ b/docs/api/modules/nickuser.rst @@ -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: diff --git a/docs/api/modules/pingresponder.rst b/docs/api/modules/pingresponder.rst new file mode 100644 index 0000000..8085567 --- /dev/null +++ b/docs/api/modules/pingresponder.rst @@ -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: diff --git a/docs/api/modules/seen.rst b/docs/api/modules/seen.rst new file mode 100644 index 0000000..5e95362 --- /dev/null +++ b/docs/api/modules/seen.rst @@ -0,0 +1,9 @@ +:mod:`Seen` --- !seen +================================ + +Provides !seen + +.. automodule:: modules.Seen + :members: + :undoc-members: + :show-inheritance: diff --git a/pyircbot/modules/AttributeStorage.py b/pyircbot/modules/AttributeStorage.py index c732747..263c448 100644 --- a/pyircbot/modules/AttributeStorage.py +++ b/pyircbot/modules/AttributeStorage.py @@ -1,4 +1,12 @@ #!/usr/bin/env python +""" +.. module:: AttributeStorage + :synopsis: An item key->value storage engine based on mysql + +.. moduleauthor:: Dave Pedu + +""" + from modulebase import ModuleBase,ModuleHook class AttributeStorage(ModuleBase): @@ -44,12 +52,17 @@ class AttributeStorage(ModuleBase): c.close() # self.getItem('xMopxShell', 'name') - # self.getAttribute('xMopxShell', 'name') - # self.setAttribute('xMopxShell', 'name', 'dave') + # self.getKey('xMopxShell', 'name') + # 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 ; 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 `i`.`id`, `i`.`item`, @@ -78,7 +91,14 @@ class AttributeStorage(ModuleBase): return {} 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 `i`.`id`, `i`.`item`, @@ -95,7 +115,7 @@ class AttributeStorage(ModuleBase): `i`.`item`=%s AND `a`.`attribute`=%s;""", - (item,attribute) + (item,key) ) row = c.fetchone() c.close() @@ -103,9 +123,17 @@ class AttributeStorage(ModuleBase): return None 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() - attribute = attribute.lower() + attribute = key.lower() # Check attribute exists c = self.db.connection.query("SELECT `id` FROM `attribute` WHERE `attribute`=%s;", (attribute)) diff --git a/pyircbot/modules/CryptoWallet.py b/pyircbot/modules/CryptoWallet.py index e25ae31..afb8968 100644 --- a/pyircbot/modules/CryptoWallet.py +++ b/pyircbot/modules/CryptoWallet.py @@ -1,4 +1,12 @@ #!/usr/bin/env python +""" +.. module:: Error + :synopsis: Module to provide a multi-type cryptocurrency wallet + +.. moduleauthor:: Dave Pedu + +""" + from modulebase import ModuleBase,ModuleHook import time import hashlib @@ -44,7 +52,7 @@ class CryptoWallet(ModuleBase): self.checkUserHasWallet(prefix.nick, cmd.args[0]) # 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])) def handle_getbal(self, args, prefix, trailing, cmd): @@ -69,7 +77,7 @@ class CryptoWallet(ModuleBase): self.checkUserHasWallet(prefix.nick, cmd.args[0]) # 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 if walletname: client = rpc.getRpc(cmd.args[0].lower()) @@ -98,13 +106,13 @@ class CryptoWallet(ModuleBase): self.checkUserHasWallet(prefix.nick, cmd.args[0]) # 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: self.bot.act_PRIVMSG(prefix.nick, ".withdraw: You need to set a withdraw address before withdrawing. Try .setaddr") return # 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 client = rpc.getRpc(cmd.args[0].lower()) @@ -154,7 +162,7 @@ class CryptoWallet(ModuleBase): # Just make sure they have a wallet 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)) def handle_curinfo(self, args, prefix, trailing, cmd): @@ -178,18 +186,18 @@ class CryptoWallet(ModuleBase): # Ensure the user has a wallet in the client attr,login,rpc = self.getMods() 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] - attr.setAttribute(username, "cryptowallet-account-%s"%currency, randName) + attr.setKey(username, "cryptowallet-account-%s"%currency, randName) # Generate a deposit addr to nudge the wallet wallet = rpc.getRpc(currency.lower()) address = wallet.getAcctAddr(randName) - attr.setAttribute(username, "cryptowallet-depoaddr-%s"%currency, address) - elif attr.getAttribute(username, "cryptowallet-depoaddr-%s"%currency)==None: - walletName = attr.getAttribute(username, "cryptowallet-account-%s"%currency) + attr.setKey(username, "cryptowallet-depoaddr-%s"%currency, address) + elif attr.getKey(username, "cryptowallet-depoaddr-%s"%currency)==None: + walletName = attr.getKey(username, "cryptowallet-account-%s"%currency) wallet = rpc.getRpc(currency.lower()) 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): diff --git a/pyircbot/modules/CryptoWalletRPC.py b/pyircbot/modules/CryptoWalletRPC.py index c331906..7d3da5f 100644 --- a/pyircbot/modules/CryptoWalletRPC.py +++ b/pyircbot/modules/CryptoWalletRPC.py @@ -1,4 +1,12 @@ #!/usr/bin/env python +""" +.. module:: CryptoWalletRPC + :synopsis: Module capable of operating bitcoind-style RPC. Provided as a service. + +.. moduleauthor:: Dave Pedu + +""" + from modulebase import ModuleBase,ModuleHook from bitcoinrpc.authproxy import AuthServiceProxy from math import floor diff --git a/pyircbot/modules/DogeDice.py b/pyircbot/modules/DogeDice.py index 80cc7a5..32d0313 100644 --- a/pyircbot/modules/DogeDice.py +++ b/pyircbot/modules/DogeDice.py @@ -1,4 +1,12 @@ #!/usr/bin/env python +""" +.. module:: DogeDice + :synopsis: Module to provide a game for gambling Dogecoin + +.. moduleauthor:: Dave Pedu + +""" + from modulebase import ModuleBase,ModuleHook import random import yaml @@ -23,7 +31,7 @@ class DogeDice(ModuleBase): def gotMsg(self, args, prefix, trailing): prefixObj = self.bot.decodePrefix(prefix) # Ignore messages from users not logged in - loggedinfrom = self.attr.getAttribute(prefixObj.nick, "loggedinfrom") + loggedinfrom = self.attr.getKey(prefixObj.nick, "loggedinfrom") if loggedinfrom==None: # Send them a hint? return @@ -104,7 +112,7 @@ class gameObj: if cmd: if len(self.players)-1 < self.maxPlayers: 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: self.master.bot.act_PRIVMSG(self.channel, "%s: You don't have enough DOGE!" % (prefix.nick)) return @@ -194,7 +202,7 @@ class gameObj: elif self.step == 4: pass - #senderIsOp = self.master.attr.getAttribute(prefix.nick, "op")=="yes" + #senderIsOp = self.master.attr.getKey(prefix.nick, "op")=="yes" def clearTimer(self, timer): if timer: timer.cancel() diff --git a/pyircbot/modules/DogeRPC.py b/pyircbot/modules/DogeRPC.py index 16e4512..48db988 100644 --- a/pyircbot/modules/DogeRPC.py +++ b/pyircbot/modules/DogeRPC.py @@ -1,4 +1,12 @@ #!/usr/bin/env python +""" +.. module:: DogeRPC + :synopsis: Provides a service for interacting with dogecoind. + +.. moduleauthor:: Dave Pedu + +""" + from modulebase import ModuleBase,ModuleHook from bitcoinrpc.authproxy import AuthServiceProxy diff --git a/pyircbot/modules/DogeScramble.py b/pyircbot/modules/DogeScramble.py index 44c923f..c3fea5b 100644 --- a/pyircbot/modules/DogeScramble.py +++ b/pyircbot/modules/DogeScramble.py @@ -1,4 +1,12 @@ #!/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 + +""" + from modulebase import ModuleBase,ModuleHook import random import yaml @@ -32,7 +40,7 @@ class DogeScramble(ModuleBase): if channel[0] == "#": # Ignore messages from users without a dogewallet password prefixObj = self.bot.decodePrefix(prefix) - if self.attr.getAttribute(prefixObj.nick, "password")==None: + if self.attr.getKey(prefixObj.nick, "password")==None: return if not channel in self.games: self.games[channel]=scrambleGame(self, channel) @@ -98,7 +106,7 @@ class scrambleGame: prefix = self.master.bot.decodePrefix(prefix) 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) if cmd and not self.running: @@ -114,8 +122,8 @@ class scrambleGame: if self.currentWord and trailing.strip().lower() == self.currentWord: # Get winner withdraw address - useraddr = self.master.attr.getAttribute(prefix.nick, "dogeaddr") - userwallet = self.master.attr.getAttribute(prefix.nick, "dogeaccountname") + useraddr = self.master.attr.getKey(prefix.nick, "dogeaddr") + userwallet = self.master.attr.getKey(prefix.nick, "dogeaccountname") self.master.bot.act_PRIVMSG(self.channel, "%s got the word - %s!" % (sender, self.currentWord)) diff --git a/pyircbot/modules/DogeWallet.py b/pyircbot/modules/DogeWallet.py index a70daf3..62e78f5 100644 --- a/pyircbot/modules/DogeWallet.py +++ b/pyircbot/modules/DogeWallet.py @@ -1,4 +1,12 @@ #!/usr/bin/env python +""" +.. module:: DogeWallet + :synopsis: Module to provide a Dogecoin wallet + +.. moduleauthor:: Dave Pedu + +""" + from modulebase import ModuleBase,ModuleHook import time import hashlib @@ -27,14 +35,14 @@ class DogeWallet(ModuleBase): if len(cmd.args)==0: self.bot.act_PRIVMSG(prefix.nick, ".setpass: usage: \".setpass newpass\" or \".setpass oldpass newpass\"") else: - oldpass = self.attr.getAttribute(prefix.nick, "password") + oldpass = self.attr.getKey(prefix.nick, "password") 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]) else: if len(cmd.args)==2: 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]) else: 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.") cmd = self.bot.messageHasCommand(".setdogeaddr", trailing) if cmd: - userpw = self.attr.getAttribute(prefix.nick, "password") + userpw = self.attr.getKey(prefix.nick, "password") if userpw==None: self.bot.act_PRIVMSG(prefix.nick, ".setdogeaddr: You must first set a password with .setpass") else: if len(cmd.args)==2: 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]) # 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] - self.attr.setAttribute(prefix.nick, "dogeaccountname", randName) + self.attr.setKey(prefix.nick, "dogeaccountname", randName) else: self.bot.act_PRIVMSG(prefix.nick, ".setdogeaddr: incorrect password.") @@ -62,14 +70,14 @@ class DogeWallet(ModuleBase): cmd = self.bot.messageHasCommand(".getdogebal", trailing) if cmd: - userpw = self.attr.getAttribute(prefix.nick, "password") + userpw = self.attr.getKey(prefix.nick, "password") if userpw==None: self.bot.act_PRIVMSG(prefix.nick, ".getdogebal: You must first set a password with .setpass") else: if len(cmd.args)==1: if userpw == cmd.args[0]: ################# - walletname = self.attr.getAttribute(prefix.nick, "dogeaccountname") + walletname = self.attr.getKey(prefix.nick, "dogeaccountname") amount = 0.0 if walletname: amount = self.doge.getBal(walletname) @@ -84,8 +92,8 @@ class DogeWallet(ModuleBase): cmd = self.bot.messageHasCommand(".withdrawdoge", trailing) if cmd: - userpw = self.attr.getAttribute(prefix.nick, "password") - useraddr = self.attr.getAttribute(prefix.nick, "dogeaddr") + userpw = self.attr.getKey(prefix.nick, "password") + useraddr = self.attr.getKey(prefix.nick, "dogeaddr") if userpw==None: self.bot.act_PRIVMSG(prefix.nick, ".withdrawdoge: You must first set a password with .setpass") elif useraddr==None: @@ -94,7 +102,7 @@ class DogeWallet(ModuleBase): if len(cmd.args)==2: if userpw == cmd.args[0]: ################# - walletname = self.attr.getAttribute(prefix.nick, "dogeaccountname") + walletname = self.attr.getKey(prefix.nick, "dogeaccountname") walletbal = self.doge.getBal(walletname) desiredAmount = float(cmd.args[1]) @@ -115,14 +123,14 @@ class DogeWallet(ModuleBase): cmd = self.bot.messageHasCommand(".getdepositaddr", trailing) if cmd: - userpw = self.attr.getAttribute(prefix.nick, "password") + userpw = self.attr.getKey(prefix.nick, "password") if userpw==None: self.bot.act_PRIVMSG(prefix.nick, ".getdepositaddr: You must first set a password with .setpass") else: if len(cmd.args)==1: if userpw == cmd.args[0]: ################# - walletname = self.attr.getAttribute(prefix.nick, "dogeaccountname") + walletname = self.attr.getKey(prefix.nick, "dogeaccountname") addr = self.doge.getAcctAddr(walletname) 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) if cmd: - userpw = self.attr.getAttribute(prefix.nick, "password") + userpw = self.attr.getKey(prefix.nick, "password") if userpw==None: self.bot.act_PRIVMSG(prefix.nick, ".login: You must first set a password with .setpass") else: if len(cmd.args)==1: 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) ################# else: @@ -151,11 +159,11 @@ class DogeWallet(ModuleBase): self.bot.act_PRIVMSG(prefix.nick, ".login: usage: \".login password\"") cmd = self.bot.messageHasCommand(".logout", trailing) if cmd: - loggedin = self.attr.getAttribute(prefix.nick, "loggedinfrom") + loggedin = self.attr.getKey(prefix.nick, "loggedinfrom") if loggedin == None: self.bot.act_PRIVMSG(prefix.nick, ".logout: You must first be logged in") 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.") def md5(self, data): diff --git a/pyircbot/modules/DuckHunt.py b/pyircbot/modules/DuckHunt.py index c7921a9..599f8cf 100644 --- a/pyircbot/modules/DuckHunt.py +++ b/pyircbot/modules/DuckHunt.py @@ -1,4 +1,12 @@ #!/usr/bin/env python +""" +.. module:: DuckHunt + :synopsis: An animal hunting IRC game + +.. moduleauthor:: Dave Pedu + +""" + from modulebase import ModuleBase,ModuleHook import time import yaml diff --git a/pyircbot/modules/GameBase.py b/pyircbot/modules/GameBase.py index ff3c662..2727e66 100644 --- a/pyircbot/modules/GameBase.py +++ b/pyircbot/modules/GameBase.py @@ -1,4 +1,12 @@ #!/usr/bin/env python +""" +.. module:: GameBase + :synopsis: A codebase for making IRC games + +.. moduleauthor:: Dave Pedu + +""" + from modulebase import ModuleBase,ModuleHook import random import yaml @@ -21,7 +29,7 @@ class GameBase(ModuleBase): def gotMsg(self, args, prefix, trailing): prefixObj = self.bot.decodePrefix(prefix) # 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? return else: @@ -54,7 +62,7 @@ class gameObj: prefix = self.master.bot.decodePrefix(prefix) pass - #senderIsOp = self.master.attr.getAttribute(prefix.nick, "op")=="yes" + #senderIsOp = self.master.attr.getKey(prefix.nick, "op")=="yes" def gameover(self): pass diff --git a/pyircbot/modules/MySQL.py b/pyircbot/modules/MySQL.py index ca20023..4852947 100644 --- a/pyircbot/modules/MySQL.py +++ b/pyircbot/modules/MySQL.py @@ -1,4 +1,12 @@ #!/usr/bin/env python +""" +.. module:: MySQL + :synopsis: Module providing a mysql type service + +.. moduleauthor:: Dave Pedu + +""" + from modulebase import ModuleBase,ModuleHook import sys @@ -39,6 +47,13 @@ class Connection: return False 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() if len(args)==0: c.execute(queryText) @@ -57,6 +72,11 @@ class Connection: return c 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() return self.connection.escape_string(s) diff --git a/pyircbot/modules/NickUser.py b/pyircbot/modules/NickUser.py index 20e151d..240bf46 100644 --- a/pyircbot/modules/NickUser.py +++ b/pyircbot/modules/NickUser.py @@ -1,4 +1,12 @@ #!/usr/bin/env python +""" +.. module:: NickUser + :synopsis: A module providing a simple login/logout account service + +.. moduleauthor:: Dave Pedu + +""" + from modulebase import ModuleBase,ModuleHook import time import hashlib @@ -11,7 +19,7 @@ class NickUser(ModuleBase): def check(self, nick, hostname): attr = self.bot.getBestModuleForService("attributes") - loggedin = attr.getAttribute(nick, "loggedinfrom") + loggedin = attr.getKey(nick, "loggedinfrom") if hostname==loggedin: return True return False @@ -36,14 +44,14 @@ class NickUser(ModuleBase): self.bot.act_PRIVMSG(prefix.nick, ".setpass: usage: \".setpass newpass\" or \".setpass oldpass newpass\"") else: attr = self.bot.getBestModuleForService("attributes") - oldpass = attr.getAttribute(prefix.nick, "password") + oldpass = attr.getKey(prefix.nick, "password") 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]) else: if len(cmd.args)==2: 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]) else: self.bot.act_PRIVMSG(prefix.nick, ".setpass: Old password incorrect.") @@ -53,14 +61,14 @@ class NickUser(ModuleBase): cmd = self.bot.messageHasCommand(".login", trailing) if cmd: attr = self.bot.getBestModuleForService("attributes") - userpw = attr.getAttribute(prefix.nick, "password") + userpw = attr.getKey(prefix.nick, "password") if userpw==None: self.bot.act_PRIVMSG(prefix.nick, ".login: You must first set a password with .setpass") else: if len(cmd.args)==1: 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) ################# else: @@ -70,11 +78,11 @@ class NickUser(ModuleBase): cmd = self.bot.messageHasCommand(".logout", trailing) if cmd: attr = self.bot.getBestModuleForService("attributes") - loggedin = attr.getAttribute(prefix.nick, "loggedinfrom") + loggedin = attr.getKey(prefix.nick, "loggedinfrom") if loggedin == None: self.bot.act_PRIVMSG(prefix.nick, ".logout: You must first be logged in") 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.") def md5(self, data): diff --git a/pyircbot/modules/NyanThread.py b/pyircbot/modules/NyanThread.py deleted file mode 100644 index d25a25f..0000000 --- a/pyircbot/modules/NyanThread.py +++ /dev/null @@ -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'([0-9]+)') - self.messagepattern = re.compile(r'([^<]+)', flags=re.IGNORECASE) - self.linkmessage = re.compile(r'') - - 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 diff --git a/pyircbot/modules/PingResponder.py b/pyircbot/modules/PingResponder.py index 2f1b207..9344d51 100644 --- a/pyircbot/modules/PingResponder.py +++ b/pyircbot/modules/PingResponder.py @@ -1,4 +1,12 @@ #!/usr/bin/env python +""" +.. module:: PingResponder + :synopsis: Module to repsond to irc server PING requests + +.. moduleauthor:: Dave Pedu + +""" + from modulebase import ModuleBase,ModuleHook class PingResponder(ModuleBase): diff --git a/pyircbot/modules/Seen.py b/pyircbot/modules/Seen.py index 412c676..c2a0c74 100644 --- a/pyircbot/modules/Seen.py +++ b/pyircbot/modules/Seen.py @@ -1,4 +1,12 @@ #!/usr/bin/env python +""" +.. module:: Seen + :synopsis: Provides !seen + +.. moduleauthor:: Dave Pedu + +""" + from modulebase import ModuleBase,ModuleHook import sqlite3 import time