Transfusion

Extremely beta code for NFO rush IRC bot

Mar 18th, 2013
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. from ircutils import bot, start_all
  2. import os
  3. import subprocess
  4. import urllib
  5. import base64
  6. class yapib(bot.SimpleBot):
  7. def __init__(self, nick):
  8. bot.SimpleBot.__init__(self, nick)
  9. self.nick = "NFO_Bot"
  10. self.real_name = "Based on http://github.com/Transfusion/yapib"
  11. self.user = "cutie"
  12. self["any"].add_handler(self.print_line)
  13. self.verbose = False
  14.  
  15. def print_line(self, client, event):
  16. kwds = {
  17. "cmd": event.command,
  18. "src": event.source,
  19. "tgt": event.target,
  20. "params": event.params
  21. }
  22. print "[{cmd}] s={src!r} t={tgt!r} p={params}".format(**kwds)
  23. def on_channel_message(self, event):
  24. tx = event.message.split()
  25. rx = tx[0].upper()
  26. params = tx[1:]
  27.  
  28.  
  29. if event.message.startswith("!searchnfo"):
  30. new_list = []
  31. newlist = []
  32. newlist1 = []
  33. htmlSource = urllib.urlopen("http://nforush.net/scene-release/dupecheck-result.html?name="+params[0]+"&sys=0&submit=SEARCH").read(200000)
  34. for chunk in htmlSource.lower().split('href=')[1:]:
  35. indexes = [i for i in [chunk.find('"',1),chunk.find('>'),chunk.find(' ')] if i>-1]
  36. new_list.append(chunk[:min(indexes)])
  37.  
  38. i = 0
  39. for i in range(i, len(new_list), 1):
  40. if new_list[i].startswith('"nfo.html?rls='):
  41. u = new_list[i].replace('&', '&')+"&view=image"
  42. newlist.append(u)
  43. else: pass
  44.  
  45.  
  46. for item in newlist: #remove duplicates
  47. if item not in newlist1:
  48. newlist1.append(item)
  49. else: pass
  50.  
  51. a = 0
  52. for a in range(a, len(newlist1), 1):
  53. self.send_message(event.target, str(newlist1[a][1:]))# or send to IRC, or whatever...
  54. print newlist1[a][1:]
  55. else: pass
  56.  
  57. if event.message.startswith("!fetchnfo"):
  58. new_list = []
  59. newlist = []
  60. newlist1 = []
  61. htmlSource = urllib.urlopen("http://nforush.net/"+params[0]).read(200000)
  62. for chunk in htmlSource.lower().split('img src=')[1:]:
  63. indexes = [i for i in [chunk.find('"',1),chunk.find('>'),chunk.find(' ')] if i>-1]
  64. new_list.append(chunk[:min(indexes)])
  65. new_list.append(chunk[:min(indexes)])
  66.  
  67. i = 0
  68. for i in range(i, len(new_list), 1):
  69. if new_list[i].startswith('"nfo.php?release='):
  70. u = new_list[i].replace('&', '&')
  71. newlist.append(u)
  72. else: pass
  73.  
  74.  
  75. for item in newlist: #remove duplicates
  76. if item not in newlist1:
  77. newlist1.append(item)
  78. else: pass
  79.  
  80. a = 0
  81. for a in range(a, len(newlist1), 1):
  82.  
  83. z = "http://nforush.net/"+newlist1[a][1:]# or send to IRC, or whatever...
  84. a = str(base64.urlsafe_b64encode(os.urandom(30)))
  85. urllib.urlretrieve(z, a+".png")
  86.  
  87. os.system('convert '+a+'.png'+' -background black -flatten /var/www/temp/'+a+'.png')
  88. self.send_message(event.target, 'Generated NFO: '+'http://base.node3.hpc.tw:81/temp/'+a+'.png')
  89.  
  90.  
  91.  
  92.  
  93. if __name__ == "__main__":
  94. instance = yapib("NFO_Bot")
  95. instance.connect("main.node2.hpc.tw", port=60124, channel="#opg")
  96.  
  97. start_all()
Add Comment
Please, Sign In to add comment