Advertisement
Guest User

Bot Code

a guest
Aug 19th, 2016
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.36 KB | None | 0 0
  1. ####################################
  2. ##Test Bot ##
  3. ##Credit: Char ##
  4. ####################################
  5.  
  6. ##This is where you put your imports
  7. import ch
  8. import requests
  9. import os
  10. import sys
  11. import urllib
  12. import time
  13. import traceback
  14. import json
  15. import re
  16. import cgi
  17. import random
  18. import datetime
  19. import binascii
  20.  
  21. if sys.version_info[0] > 2:
  22. import urllib.request as urlreq
  23. else:
  24. import urllib2 as urlreq
  25.  
  26. ############
  27. ##Variables
  28. API_KEY = "AIzaSyA98i5h1IXWNAKVl9TAAJgxVhFJgBJoLZc"
  29. prefix = "!"
  30. username = input("Username: ")
  31. password = input("Password: ")
  32. rooms = ["yt"]
  33.  
  34.  
  35.  
  36. ###########################################################
  37. ##Startup
  38.  
  39. class bot(ch.RoomManager):
  40. def onInit(self):
  41. self.setNameColor("ffffff")
  42. self.setFontColor("ffffff")
  43. self.setFontFace("Arial")
  44. self.setFontSize(11)
  45. self.enableBg()
  46. self.enableRecording()
  47.  
  48. def onConnect(self, room):
  49. self.setNameColor("ffffff")
  50. self.setFontColor("ffffff")
  51. self.setFontFace("Arial")
  52. self.setFontSize(9)
  53. self.enableBg()
  54. self.enableRecording()
  55. print("[INFO] Connected to "+room.name)
  56.  
  57. def onReconnect(self, room):
  58. self.setNameColor("ffffff")
  59. self.setFontColor("ffffff")
  60. self.setFontFace("Arial")
  61. self.setFontSize(9)
  62. self.enableBg()
  63. self.enableRecording()
  64. print("[INFO] Reconnected to : "+room.name)
  65. room.message("Reconnected")
  66.  
  67. def onDisconnect(self, room):
  68. self.setNameColor("ffffff")
  69. self.setFontColor("ffffff")
  70. self.setFontFace("Arial")
  71. self.setFontSize(9)
  72. self.enableBg()
  73. self.enableRecording()
  74. print("[INFO] Disconnected from : "+room.name)
  75.  
  76.  
  77. def onFloodWarning(self, room):
  78. print("[INFO] FloodWarning in : "+room.name)
  79. time.sleep(5)
  80. room.reconnect()
  81.  
  82. def onJoin(self, room, user):
  83. if user.name.lower() not in ignorejoin and greet == True:
  84. nam = user.name.lower()
  85. namm = user.name.title()
  86. room.message("http://fp.chatango.com/profileimg/"+nam[0]+"/"+nam[1]+"/"+nam+"/full.jpg"+" ["+namm+"]"+" has joined the room! ~ ")
  87. lurkers.append(user.name)
  88.  
  89. def onBan(self, room, user, target):
  90. room.message(target.name.title()+" was banned by "+user.name.title())
  91. print("[INFO] "+target.name.title()+" was banned by "+user.name.title()+" in "+room.name.title())
  92.  
  93. def onUnban(self, room, user, target):
  94. room.message(target.name.title()+" has been unbanned by "+user.name.title())
  95. print("[INFO] "+target.name.title()+" was unbanned by "+user.name.title()+" in "+room.name.title())
  96.  
  97.  
  98.  
  99.  
  100. # used if message is posted in chatroom
  101. def onMessage(self, room, user, message):
  102.  
  103. #######################################
  104. # Split message into command and args
  105. #######################################
  106. msgdata = message.body.split(" ",1)
  107. if len(msgd) > 1:
  108. cmd, args = msgd[0], msgd[1] # if command and args
  109. else:
  110. cmd, args = msgd[0],"" # if command and no args
  111. cmd=cmd.lower()
  112.  
  113. #################
  114. # Used Prefix
  115. #################
  116. if len(cmd) >0:
  117. if cmd[0]==prefix:
  118. used_prefix = True
  119. cmd = cmd[1:]
  120. else:
  121. used_prefix = False
  122. else:
  123. return
  124.  
  125. ##########################################################
  126. ##Detection
  127.  
  128. #Detect Message
  129. if not used_prefix:
  130. print(("[TEXT/MESSAGE]"), ("[")+room.name+("]"), user.name, (":"), message.body, (":"), message.ip)
  131.  
  132. #Detect Command
  133. if used_prefix:
  134. print(("[COMMAND]"), ("[")+room.name+("]"), user.name, (":"), cmd, (":"), args, (":"), message.ip)
  135.  
  136. #########################
  137. ##Commands
  138.  
  139.  
  140. if used_prefix and cmd=="say":
  141. if len(args)>0:
  142. room.message(user.name.title()+"Told me to say: "+args)
  143. else:
  144. room.message("You didn't say anything moron!")
  145.  
  146.  
  147. elif used_prefix and cmd=="yt" and self.getAccess(user) >=1 and len(args)>0:
  148. try:
  149. string=args.lower()
  150. def search(string):
  151. apikey = API_KEY
  152. api = requests.get("https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=1&order=relevance&q=%s&safeSearch=none&key=%s" % (string, apikey)).json()
  153. id = api['items'][0]['id']['videoId']
  154. link = "https://www.youtube.com/watch?v=%s" % id
  155. title = api['items'][0]['snippet']['title']
  156. auth = api['items'][0]['snippet']['channelTitle']
  157. try:
  158. return title + " by " + auth + " " + link
  159. except:
  160. return "fucked your shit up"
  161. room.message(search(string))
  162. except:
  163. room.message("You dun fucked up kid")
  164. print(traceback.format_exc())
  165.  
  166.  
  167. ###########################
  168. ##Bot Start Code
  169.  
  170. if __name__ == "__main__":
  171. bot.easy_start(rooms, username, password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement