Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

forgot modules folder, update to locker, proper @lock and @unlock

  • Loading branch information...
commit 97a03bd45942c1c33da2e3cd8a2f58a2ab893e12 1 parent adb5fef
@Ferus authored
View
43 Commands.py
@@ -2,6 +2,7 @@
import re
import pluginLoader as pL
+from Plugins import CommandLock
class Commands():
def __init__(self, nick=None, parser=None, allowed=None):
@@ -18,7 +19,7 @@ def __init__(self, nick=None, parser=None, allowed=None):
self.parser = parser
self.allowed = allowed
- self.Locked = False
+ self.Locker = CommandLock.Locker(-1)
self.cmds = {"^@help": [self.Help, 5, False]
,"^@plugins": [self.Plugins, 5, False]
@@ -26,6 +27,8 @@ def __init__(self, nick=None, parser=None, allowed=None):
,"^@join": [self.Join, 3, True]
,"^@part": [self.Part, 3, True]
,"^@access": [self.Access, 0, True]
+ ,"^@lock": [self.Lock, 0, True]
+ ,"^@unlock": [self.Unlock, 0, True]
}
self.helpstrings = {
@@ -33,17 +36,19 @@ def __init__(self, nick=None, parser=None, allowed=None):
#@help <ModuleName> will give specific info about a module.
"help" : """@help takes one argument, the name of a plugin in which you wish to get help for.
To get a list of loaded plugins, use '@plugins'
- """,
- "plugins" : "Notices the user with a list of plugins available. You can also '@help <PluginName>' for specific info",
- "join" : "Tells {0} to join one or more channel(s). Takes channels separated by a comma with or without the leading hashtag.".format(self.nick),
- "part" : "Tells {0} to part one or more channel(s). Takes channels separated by a comma with or without the leading hashtag.".format(self.nick),
- "quit" : "Tells {0} to shutdown.".format(self.nick),
- "access":"""Allows the owner(s) (Access level 0) to modify access levels per user/hostmask
- The default level for ignore is anything above 5, but this can be changed.
- add: Used to add/change access of a person. Takes 3 arguments, Nick, Host (or 'none'), and an Access Level.
- del: Used to revoke access from a user. Takes 1 argument, Nick.
- show: Used to print the access for a user to a channel. Takes 1 argument, Nick.
- """,
+ """
+ ,"plugins" : "Notices the user with a list of plugins available. You can also '@help <PluginName>' for specific info"
+ ,"join" : "Tells {0} to join one or more channel(s). Takes channels separated by a comma with or without the leading hashtag.".format(self.nick)
+ ,"part" : "Tells {0} to part one or more channel(s). Takes channels separated by a comma with or without the leading hashtag.".format(self.nick)
+ ,"quit" : "Tells {0} to shutdown.".format(self.nick)
+ ,"access": """Allows the owner(s) (Access level 0) to modify access levels per user/hostmask
+ The default level for ignore is anything above 5, but this can be changed.
+ add: Used to add/change access of a person. Takes 3 arguments, Nick, Host (or 'none'), and an Access Level.
+ del: Used to revoke access from a user. Takes 1 argument, Nick.
+ show: Used to print the access for a user to a channel. Takes 1 argument, Nick.
+ """
+ ,"lock": "Locks all commands down to Owner access only."
+ ,"unlock": "Unlocks all commands."
}
self.loadedplugins = []
@@ -159,3 +164,17 @@ def Access(self, msg, sock, users, _allowed):
except Exception, e:
sock.notice(Nick, "Format for 'access' is: `access add/del Nick Ident@host Level`")
print("* [Access] Error:\n* [Access] {0}".format(str(e)))
+
+ def Lock(self, msg, sock, users, _allowed):
+ if not self.Locker.Locked:
+ if self.Locker.Lock():
+ sock.say(msg[3], "Locking successful.")
+ else:
+ sock.notice(msg[0], "I'm already locked you derp.")
+
+ def Unlock(self, msg, sock, users, _allowed):
+ if self.Locker.Locked:
+ if not self.Locker.Unlock():
+ sock.say(msg[3], "Unlocking successful.")
+ else:
+ sock.notice(msg[0], "I'm already unlocked you derp.")
View
3  Parser.py
@@ -142,6 +142,9 @@ def Privmsg(self, msg):
and if they have access, execute the command. Regex based commands too. :)
'''
print(u"* [Privmsg] [{0}] <{1}> {2}".format(Location, Nick, Text))
+ if self.command.Locker.Locked and Nick != self.allowed.Owner[0]:
+ self.sock.notice(Nick, "Sorry but I'm locked bro.")
+ return None
for comm in self._commands: #Loop through every one.
if re.search(comm+u"(\s|$)", Text): #If we match a command
check = self.allowed.levelCheck(Nick)[1] #Start an access check
View
17 Plugins/CommandLock.py
@@ -15,6 +15,14 @@
Do_Something()
Locker.Lock()
'''
+
+'''
+Changelog:
+March 15:
++ Negative integers lock forever until Unlock() is called, Zero defaults to 5.
++ Return self.Locked after calling.
+'''
+
class Locker(object):
def __init__(self, Time=None):
self.Time = Time if Time and type(Time) == int else 5
@@ -24,9 +32,12 @@ def __init__(self, Time=None):
def Lock(self):
if not self.Locked:
self.Locked = True
- t = Timer(self.Time, self.Unlock, ())
- t.daemon = True
- t.start()
+ if self.Time > 0:
+ t = Timer(self.Time, self.Unlock, ())
+ t.daemon = True
+ t.start()
+ return self.Locked
def Unlock(self):
self.Locked = False
+ return self.Locked
View
294 Plugins/Modules/Torrents.py
@@ -0,0 +1,294 @@
+#!/usr/bin/env python
+
+"""
+Torrents.py by Ferus (^) @
+Opsimathia.datnode.net / Mempsimoiria.datnode.net #hacking
+Searches multiple sites for torrents based on 'user input'.
+
+Required: requests - https://github.com/kennethreitz/requests
+
+Currently Supported Websites:
+http://thepiratebay.se/
+http://demonoid.me/
+http://1337x.org/
+http://kat.ph/
+
+Each Request() call from every class
+returns a dict with the following keys:
+
+ title - The title of the torrent
+ seed - The number of seeders
+ leech - The number of leechers
+ size - Size of the torrent
+ link - http link to the .torrent file
+ empty string if not found
+ magnetlink - magnet link to torrent
+
+However if we fail to get html, we raise requests.HTTPError
+and return the error string.
+"""
+
+"""
+Released under the hLP v2 licence:
+
+dis iz hPL v2
+imho u shud uz hPL v2 but idfc mang u can uz hPL v1 i guss
+
+this is da h public license
+best license ever imho l0l
+^ tbqhz
+
+rools of da h public license (frum her on out nown az h)
+1. do whatever the fuck you want man idfk tbh imho
+2. fk off copyright lawyers
+3. gtfo my software copyright lawyers
+4. lmao u got 0wn3d xD
+5. l0l
+6. (imho) (tbh) (l0l)
+7. hunter is cool l0l
+8. h
+9. h
+11. h
+12. u cant get made at mi 4 nt havn a #10 l0l
+"""
+
+try:
+ import requests
+except ImportError:
+ import sys
+ sys.exit("This script requires requests to be installed.")
+
+import re
+
+class MissingTermsError(Exception):
+ """You failed to pass any searchterms."""
+
+class MissingCategoryError(Exception):
+ """That category does not exist."""
+
+class DefaultSearch(object):
+ def __init__(self):
+ self.SearchURL = ""
+ self.SearchCategories = {}
+ self.WhiteSpaceRegex = "\t|\n"
+ self.TorrentGroupRegex = ""
+
+ self.REGEXES = {"title": ["", 0]
+ ,"link": ["", 0]
+ ,"magnetlink": ["", 0]
+ ,"seed": ["", 0]
+ ,"leech": ["", 0]
+ ,"size": ["", 0]}
+
+ def Request(self, terms, category='all'):
+ if not terms:
+ raise MissingTermsError
+ if category not in self.SearchCategories.keys():
+ raise MissingCategoryError
+ url = self.SearchURL.format(terms, self.SearchCategories[category])
+
+ try:
+ req = requests.get(url)
+ if req.status_code != 200:
+ raise requests.HTTPError
+ return self.Parse(req.content)
+ except requests.HTTPError, e:
+ return e.message
+
+ def Parse(self, html):
+ torrentdict = {}
+ html = re.sub(self.WhiteSpaceRegex, "", html)
+ torrents = re.findall(self.TorrentGroupsRegex, html)
+ x = 0
+ while len(torrents) != 0:
+ torrent = torrents.pop(0)
+ info = {}
+ for regex in self.REGEXES.keys():
+ try:
+ info[regex] = re.findall(self.REGEXES[regex][0], torrent)[self.REGEXES[regex][1]]
+ except IndexError:
+ info[regex] = ""
+ except Exception, e:
+ info[regex] = "Error: {0}".format(repr(e))
+ torrentdict[str(x)] = info
+ x += 1
+ return torrentdict
+
+class ThePirateBaySearch(DefaultSearch):
+ """Poll ThePirateBay.
+ """
+ def __init__(self):
+ self.SearchURL = "http://thepiratebay.se/search/{0}/0/99/{1}" # Terms, Category.
+ self.SearchCategories = {
+ 'all': '0'
+
+ # Audio
+ ,'music': '101'
+ ,'audio books': '102'
+ ,'sound clips': '103'
+ ,'flac': '104'
+
+ # Video
+ ,'movies': '201'
+ ,'movies dvdr': '202'
+ ,'music videos': '203'
+ ,'movie clips': '204'
+ ,'tv shows': '205'
+ ,'handheld': '206'
+ ,'highres movies': '207'
+ ,'highres tv shows': '208'
+ ,'3d': '209'
+
+ # Applications
+ ,'windows': '301'
+ ,'mac': '302'
+ ,'unix': '303'
+ ,'handheld': '304'
+ ,'ios': '305'
+ ,'android': '306'
+
+ # Games
+ ,'pc games': '401'
+ ,'mac games': '402'
+ ,'psx': '403'
+ ,'xbox360': '404'
+ ,'wii': '405'
+ ,'handheld games': '406'
+ ,'ios games': '407'
+ ,'android games': '408'
+
+ # Porn
+ ,'porn movies': '501'
+ ,'porn movies dvdr': '502'
+ ,'porn pictures': '503'
+ ,'porn games': '504'
+ ,'porn highres movies': '505'
+ ,'porn movie clips': '506'
+
+ # Other
+ ,'e-books': '601'
+ ,'comics': '602'
+ ,'pictures': '603'
+ ,'covers': '604'
+ ,'physibles': '605'}
+
+ self.WhiteSpaceRegex = "\t|\n"
+ self.TorrentGroupsRegex = "<tr>(.*?)</tr>"
+
+ self.REGEXES = {"title": ["<div class=\"detName\"><a .*?>(.*?)</a>", 0]
+ ,"link": ["<a href=\"(http.*?)\" title=\"Download this torrent\">", 0]
+ ,"magnetlink": ["<a href=\"(magnet:.*?)\" title=\"Download this torrent using magnet\">", 0]
+ ,"seed": ["<td align=\"right\">(.*?)</td>", 0]
+ ,"leech": ["<td align=\"right\">(.*?)</td>", 1]
+ ,"size": ["<font class=\"detDesc\">.*?(Size .*?), ULed by <a.*?</a></font>", 0]}
+
+class leetxSearch(object):
+ def __init__(self):
+ self.SearchURL = "http://1337x.org/search/{0}/{1}/" # Terms, Page
+
+ def Parse(self, html):
+ torrentdict = {}
+ html = re.sub('\s{2,}', ' ', html.replace("\t", "").replace("\n", ""))
+ torrents = re.findall("<div class=\"torrentName\">(.*?)</div> <div class=\"clr\"></div>", html)
+ x = 0
+ while len(torrents) != 0:
+ torrent = torrents.pop(0)
+ info = {}
+ page, info['title'] = re.findall("<a href=\"(/torrent/.*?)\" class=\"org\">(.*?)</a>", torrent)[0]
+ info['leech'] = re.findall("<span class=\"leech\">(.*?)</span>", torrent)[0]
+ info['seed'] = re.findall("<span class=\"seed\">(.*?)</span>", torrent)[0]
+ info['size'] = re.findall("<span class=\"size\">(.*?)</span>", torrent)[0]
+
+ newhtml = requests.get("http://1337x.org"+page)
+ if newhtml.status_code != 200:
+ info['link'] = None
+ info['magnetlink'] = None
+ else:
+ newhtml = newhtml.content
+ info['link'] = "http://1337x.org" + re.findall("<a href=\"(/download/.*?)\" class=\"torrentDw\" title=\"Torrent Download\"></a>", newhtml)[0]
+ info['magnetlink'] = re.findall("<a href=\"(magnet.*?)\" class=\"magnetDw\" title=\"Magnet Download\"></a>", newhtml)[0]
+ torrentdict[str(x)] = info
+ x += 1
+ return torrentdict
+
+ def Request(self, terms, page=0):
+ if not terms:
+ raise MissingTermsError
+ url = self.SearchURL.format(terms, page)
+
+ try:
+ req = requests.get(url)
+ if req.status_code != 200:
+ raise requests.HTTPError
+ return self.Parse(req.content)
+ except requests.HTTPError, e:
+ return e.message
+
+class KickAssTorrentsSearch(DefaultSearch):
+ def __init__(self):
+ self.SearchURL = "http://kat.ph/usearch/{0}{1}" # Terms
+ self.SearchCategories = {"all": ""
+ ,"applications": "/?categories[]=applications"
+ ,"books": "/?categories[]=books"
+ ,"games": "/?categories[]=games"
+ ,"movies": "/?categories[]=movies"
+ ,"music": "/?categories[]=music"
+ ,"tv": "/?categories[]=tv"
+ ,"xxx": "/?categories[]=xxx"
+ ,"other": "/?categories[]=other"}
+
+ self.WhiteSpaceRegex = "\t|\n|<strong class=\"red\">|</strong>|<span>|</span>"
+ self.TorrentGroupsRegex = "<tr class=\"(?:even|odd)\" id=\".*?\">(.*?)</tr>"
+
+ self.REGEXES = {"title": ["<a href=\".*?\" class=\"normalgrey font12px plain bold\">(.*?)</a>", 0]
+ ,"link": ["<a title=\"Download torrent file\" href=\"(.*?)\".*?>", 0]
+ ,"magnetlink": ["<a title=\"Torrent magnet link\" href=\"(magnet.*?)\" .*?class=\"imagnet icon16\">", 0]
+ ,"seed": ["<td class=\"green center\">(.*?)</td>", 0]
+ ,"leech": ["<td class=\"red lasttd center\">(.*?)</td>", 0]
+ ,"size": ["<td class=\"nobr center\">(.*?)</td>", 0]}
+
+class DemonoidSearch(DefaultSearch):
+ def __init__(self):
+ self.SearchURL = "http://beta.demonoid.me/files/?query={0}&sort=&category={1}&external=2&quality=0" # terms, category
+ self.SearchCategories = {"all": ""
+ ,"movies": "1"
+ ,"music": "2"
+ ,"tv": "3"
+ ,"games": "4"
+ ,"applications": "5"
+ ,"misc": "6"
+ ,"pictures": "8"
+ ,"anime": "9"
+ ,"comics": "10"
+ ,"books": "11"
+ ,"music videos": "13"
+ ,"audio books": "17"}
+
+ self.WhiteSpaceRegex = "\t|\n"
+ self.TorrentGroupsRegex = "<tr(?:.*?class=\"alt\".*?)? id=\"atorr[0-9]{0,}\">(.*?</tr>.*?)</tr>"
+
+ self.REGEXES = {"title": ["<a href=\"http://beta.demonoid.me/files/details/.*?/.*?\" class=\"bl\">(.*?)(?: <span.*?</span>)?</a>", 0]
+ ,"link": ["<a href=\"(http://beta.demonoid.me/files/download/.*?/)\" class=\"download\">", 0]
+ ,"magnetlink": ["<a href=\"(http://beta.demonoid.me/files/downloadmagnet/.*?/)\" class=\"download\">", 0]
+ ,"seed": ["<td class=\"tseeders\">(.*?)</td>", 0]
+ ,"leech": ["<td class=\"tleechers\">(.*?)</td>", 0]
+ ,"size": ["<td class=\"tsize\">(.*?)</td>", 0]}
+
+def Test():
+ from pprint import pprint
+ #tpb = ThePirateBaySearch()
+ #pprint(tpb.Request("House", "tv shows"))
+
+ #leetx = leetxSearch()
+ #pprint(leetx.Request("House"))
+
+ #kat = KickAssTorrentsSearch()
+ #pprint(kat.Request("House", "tv"))
+
+ #dem = DemonoidSearch()
+ #pprint(dem.Request("House", "tv"))
+ #print("\n\n\n")
+ #pprint(dem.Request("Naruto", "anime"))
+
+if __name__ == '__main__':
+ pass
View
2  Plugins/Modules/__init__.py
@@ -0,0 +1,2 @@
+import Torrents
+__all__ = [Torrents]
View
35 Plugins/Torrent.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+from Plugins.Modules import Torrents
+from CommandLock import Locker
+
+tpbL = Locker(3)
+class ThePirateBay(Torrents.ThePirateBaySearch):
+
+ def Main(self, Message, Sock, Users, Allowed):
+ if tpbL.Locked:
+ Sock.say(Message[0], "This command is locked at the moment.")
+ return None
+
+ x = " ".join(Message[4].split()[1:])
+ try:
+ cat, terms = x.split("[")[1].split("]")
+ except:
+ cat = "all"
+ terms = x
+
+ y = self.Request(terms.strip(" "), cat)
+ for p in range(3):
+ q = "\x02[TPB]\x02 {0} - {1} [{2} Seeds/{3} Leeches] {4}".format(y[str(p)]['title'], \
+ y[str(p)]['size'], y[str(p)]['seed'], y[str(p)]['leech'], \
+ y[str(p)]['link'] if y[str(p)]['link'] else y[str(p)]['magnetlink'])
+
+ Sock.say(Message[0], q)
+ tpbL.Lock()
+
+tpb = ThePirateBay()
+
+hooks = {
+ '^@tpb': [tpb.Main, 5, False],
+ }
+
+helpstring = ""
Please sign in to comment.
Something went wrong with that request. Please try again.