Advertisement
Guest User

Untitled

a guest
Mar 16th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.64 KB | None | 0 0
  1. import ch
  2. import requests
  3. from bs4 import BeautifulSoup
  4. import urllib
  5. import time
  6. import os
  7. import threading
  8. import random
  9. import re
  10.  
  11. def compile(ster):
  12.  
  13. with open("ban.txt") as e:
  14. r=e.read().splitlines()
  15. r = filter(None, r)
  16. final=list(set(r))
  17.  
  18.  
  19. ster=ster.lower()
  20. for item in final:
  21.  
  22. if item in ster or item.capitalize() in ster or item.lower() in ster:
  23. ster=ster.replace(item,"")
  24. ster=ster.replace("."," ")
  25. y=ster.split(" ")
  26. print y
  27. for item in y:
  28. if re.search(r'[12]\d{3}', item):
  29. target_ibdex = y.index(item)
  30. ster=" ".join(y[:target_ibdex+1])
  31. break
  32.  
  33.  
  34. return ster
  35.  
  36. def getmovie():
  37.  
  38. s = requests.Session()
  39. #VLC password entered here.
  40. s.auth = ('', 'pass')# Username is blank, just provide the password
  41. r = s.get('http://localhost:8080/requests/status.xml', verify=False)
  42. #print r.text
  43. soup=BeautifulSoup(r.text,"html.parser")
  44. result = soup.find('info', {'name' :'filename'}).text
  45. #grabbing VLC filename of Movie
  46. #print result
  47. res=os.path.splitext(result)
  48. s.close()
  49. #getting IMDB results
  50.  
  51. g=compile(res[0])
  52. print g
  53. url="http://www.imdb.com/find?ref_=nv_sr_fn&q="+g+"&s=all"
  54. headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
  55. t = requests.get(url,headers=headers)
  56. soup = BeautifulSoup(t.content,"html.parser")
  57. try:
  58. result = soup.find('td', {'class' :'result_text'}).find('a')['href']
  59. link="http://www.imdb.com"+result
  60. #returns the IMDB link if found.
  61. return link
  62. except:
  63. return "No Result Found"
  64.  
  65.  
  66. class bot(ch.RoomManager):
  67.  
  68. #the bot starts
  69. def onInit(self):
  70. #self.setNameColor("FFFFFF")
  71. #self.setFontColor("FFFFFF")
  72. self.setFontFace("Times New Roman")
  73. self.setFontSize(19)
  74. #when someone joins
  75. def onJoin(self, room, user, puid):
  76. room.message(welcome(user.name))
  77. #on connectivity
  78. def onConnect(self, room):
  79. print("Connected to "+room.name)
  80. room.message("sup")
  81. #while True:
  82. # room.message("Its an Hourly Message..!!")
  83. # time.sleep(60)
  84. def onReconnect(self, room):
  85. print("Reconnected")
  86.  
  87.  
  88. #when someone messages in
  89.  
  90. def onMessage(self, room, user, message):
  91. print("[{0}] {1}: {2}".format(room.name, user.name.title(), message.body))
  92.  
  93.  
  94. #enter imgur links here
  95. links_to_imgur=["http://i.imgur.com/brqdwST.png","http://i.imgur.com/95wH1fX.jpg","http://i.imgur.com/FqmzRZG.png","http://i.imgur.com/iZzzIl1.png","http://i.imgur.com/POExwF3.jpg","http://i.imgur.com/Jev5ygL.png","http://i.imgur.com/VXCOhQV.png,","http://i.imgur.com/MQcLZfr.png","http://i.imgur.com/rY50611.png","http://i.imgur.com/S7wURDd.png","http://i.imgur.com/brqdwST.png","http://i.imgur.com/l9COjSF.png","http://i.imgur.com/ejMxc1h.png","http://i.imgur.com/APnh8u5.png","http://i.imgur.com/bMvegoz.png","http://i.imgur.com/tmKfD71.jpg","http://i.imgur.com/GUOAfvC.png","http://i.imgur.com/nW0dsaB.jpg","http://i.imgur.com/HQPI4w2.png","http://i.imgur.com/4ALL16Y.png"]
  96.  
  97. #list of words to be scanned in messages
  98. banned=["test1","test2"]
  99.  
  100. for item in banned:
  101. if item in message.body:
  102. #response to the words if found
  103. room.message("Banned word found.")
  104.  
  105.  
  106. try:
  107. cmd, args = message.body.split(" ", 1)
  108. except:
  109. cmd, args = message.body, ""
  110. #print args
  111. if cmd[0] == "/":
  112. prfx = True
  113. cmd = cmd[1:]
  114. cmd.lower()
  115.  
  116.  
  117. '''list of all commands. you can create one in the same format as below.
  118.  
  119. '''
  120. if cmd=="movie":
  121. room.message("Looking IMDB")
  122. #print getmovie()
  123. room.message(getmovie())
  124. #create a command hello
  125. elif cmd=="phrasing":
  126. room.message("http://i.imgur.com/i2yYun3.gif")
  127.  
  128. elif cmd=="help":
  129. room.message("FCTV Bot Command list")
  130. room.message("./phrasing, ./blackhole, ./imdb, ./request :Request a movie, ./quote, ./burger, ./bigguy")
  131.  
  132.  
  133.  
  134.  
  135. elif cmd=="blackhole":
  136. room.message("http://i.imgur.com/XFwsz8a.jpg, "+user.name.title())
  137. elif cmd=="request":
  138. room.message("Sure, ill try to stream that soon. "+user.name.title())
  139. a=open("request.txt","a")
  140. a.write(args+"\n")
  141. a.close()
  142. elif cmd=="imgur":
  143. random.shuffle(links_to_imgur)
  144. g=random.choice(links_to_imgur)
  145.  
  146. room.message(g)
  147.  
  148. elif cmd=="burger":
  149. room.message("*burger*")
  150.  
  151. elif cmd=="imdb":
  152. room.message("Looking IMDB")
  153. #print getmovie()
  154.  
  155. room.message(getmovie())
  156.  
  157. elif cmd=="bigguy":
  158. room.message("For you.")
  159. else:
  160. room.message("Incorrect Command.")
  161. else:
  162. prfx = False
  163.  
  164. #credentials
  165. rooms = ["troublesomegentlemen"]
  166. username = "FilthyAndroid"
  167. password = "qwerqwer1"
  168.  
  169. bot.easy_start(rooms,username,password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement