Advertisement
Guest User

@ImmaChatBot

a guest
Nov 13th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 363.79 KB | None | 0 0
  1. import telepot
  2. import random
  3. from random import shuffle
  4. import urbandict
  5. from collections import OrderedDict
  6. import string
  7. import cv2
  8. import pytz
  9. from datetime import datetime
  10. from mmap import mmap
  11. import glob
  12. from googletrans import Translator
  13. import requests
  14. import numpy as np
  15. # from model import Deeplabv3
  16. import itertools
  17. from random_words import RandomWords
  18. from collections import Counter
  19. import telegram
  20. import urllib
  21. import urllib3
  22. import datetime
  23. import threading
  24. import json
  25. import linecache
  26. #from weather import Weather, Unit
  27. import subprocess
  28. import io
  29. from matplotlib import pyplot as pltz
  30. import sys
  31. import re
  32. from threading import Thread
  33. import time
  34. from telepot.namedtuple import ReplyKeyboardMarkup, ReplyKeyboardRemove, InlineKeyboardMarkup, InlineKeyboardButton, \
  35. KeyboardButton
  36. import PIL
  37. from PIL import Image, ImageFont, ImageDraw, ImageOps, ImageFilter
  38. from PIL import ImageEnhance
  39. import datetime
  40. import os
  41. from gtts import gTTS
  42. from timezonefinder import TimezoneFinder
  43. from geopy.geocoders import GoogleV3
  44. import random
  45. import datetime
  46. from geopy import geocoders
  47. import timezonefinder, pytz
  48. from pytz import timezone
  49.  
  50. tf = TimezoneFinder()
  51. translator = Translator()
  52.  
  53.  
  54. if not os.path.exists("feedback/"):
  55. os.makedirs("feedback/")
  56.  
  57. botID = str(open('token.dat', 'r').read()).split(':')[0]
  58.  
  59. print('\u2022')
  60. startSpam = False
  61. safetyNet = False
  62.  
  63.  
  64. def handle(msg):
  65. print('1')
  66. stickerExecute = True
  67. global safetyNet
  68. global edited
  69. global startSpam
  70. global USER
  71. global message
  72. global meProfileUser
  73. global meProfileName
  74. #FILES AND DIRECTORIES
  75. if 'from' in msg:
  76. messageFromID = msg['from']['id']
  77. else:
  78. messageFromID = 'None'
  79. if 'type' in msg:
  80. messageType = msg['chat']['type']
  81. else:
  82. messageType = "None"
  83. try:
  84. messageType = msg['chat']['type']
  85. except:
  86. messagType = 'None'
  87. if messageType != 'private':
  88. isPrivateMessage = False
  89. toSend = True
  90. isGroup = True
  91. else:
  92. isPrivateMessage = True
  93. toSend = False
  94. isGroup = False
  95.  
  96. if 'chat' in msg:
  97. if str(msg['chat']['id']) == '-1001347177423':
  98. if 'True' in open('data/debug.txt', 'r').read():
  99. chat_id = str(-1001310035457)
  100. else:
  101. chat_id = str(msg['chat']['id'])
  102. else:
  103. chat_id = str(msg['chat']['id'])
  104. else:
  105. chat_id = "None"
  106. if 'data' in msg:
  107. global warnd
  108. isInlineResponse = True
  109. messageInlineData = msg['data']
  110. print(messageInlineData)
  111. else:
  112. isInlineResponse = False
  113. messageInlineData = 'None'
  114. global warnd
  115. global promoted
  116. if 'message_id' in msg:
  117. messageID = str(msg['message_id'])
  118. else:
  119. messageID = 'None'
  120. if messageType != 'private':
  121. if not os.path.exists(str(chat_id)):
  122. os.makedirs(str(chat_id))
  123. os.makedirs(str(chat_id) + "/messages/")
  124. os.makedirs(str(chat_id) + "/rooms/")
  125. os.makedirs(str(chat_id) + "/data/")
  126. if not os.path.exists("data/"):
  127. os.makedirs("data/")
  128. if not os.path.exists("login/"):
  129. os.makedirs("login/")
  130. if not os.path.exists("rooms/"):
  131. os.makedirs("rooms/")
  132. if os.path.isfile("data/usernames.txt") == False:
  133. open("data/usernames.txt", "w").write("admin\nspoon\n")
  134. if os.path.isfile("data/listofgroups.data") == False:
  135. open("data/listofgroups.data", "w").write("")
  136. if os.path.isfile("data/listofusers.data") == False:
  137. open("data/listofusers.data", "w").write("")
  138. if os.path.isfile(str(chat_id) + "/data/adminlist.data") == False:
  139. open(str(chat_id) + "/data/adminlist.data", "w").write("")
  140. if os.path.isfile(str(chat_id) + "/data/numberone.txt") == False:
  141. open(str(chat_id) + "/data/numberone.txt", "w").write("ImmaChatBot\nImmaChatBot\n0")
  142. if os.path.isfile(str(chat_id) + "/data/numbertwo.txt") == False:
  143. open(str(chat_id) + "/data/numbertwo.txt", "w").write("ImmaChatBot2\nImmaChatBot2\n0")
  144. if os.path.isfile(str(chat_id) + "/data/numberthree.txt") == False:
  145. open(str(chat_id) + "/data/numberthree.txt", "w").write("ImmaChatBot3\nImmaChatBot3\n0")
  146. if os.path.isfile(str(chat_id) + "/data/tts.txt") == False:
  147. open(str(chat_id) + "/data/tts.txt", "w").write("True")
  148. if os.path.isfile(str(chat_id) + "/data/imagecolor.txt") == False:
  149. open(str(chat_id) + "/data/imagecolor.txt", "w").write("black")
  150. if os.path.isfile(str(chat_id) + "/data/compref.txt") == False:
  151. open(str(chat_id) + "/data/compref.txt", "w").write("/")
  152. if os.path.isfile(str(chat_id) + "/data/textcolor.txt") == False:
  153. open(str(chat_id) + "/data/textcolor.txt", "w").write("white")
  154. if os.path.isfile(str(chat_id) + "/data/gamelimit.txt") == False:
  155. open(str(chat_id) + "/data/gamelimit.txt", "w").write("30")
  156. if os.path.isfile("data/debug.txt") == False:
  157. open("data/debug.txt", "w").write("False")
  158. if os.path.isfile(str(chat_id) + "/data/greet.txt") == False:
  159. open(str(chat_id) + "/data/greet.txt", "w").write("Text")
  160. if os.path.isfile(str(chat_id) + "/data/games.txt") == False:
  161. open(str(chat_id) + "/data/games.txt", "w").write("True")
  162. if os.path.isfile(str(chat_id) + "/data/word.txt") == False:
  163. open(str(chat_id) + "/data/word.txt", "w").write("True")
  164. if os.path.isfile(str(chat_id) + "/data/admin.txt") == False:
  165. open(str(chat_id) + "/data/admin.txt", "w").write
  166. if os.path.isfile(str(chat_id) + "/data/jokes.txt") == False:
  167. open(str(chat_id) + "/data/jokes.txt", "w").write("False")
  168. if os.path.isfile(str(chat_id) + "/data/limit.txt") == False:
  169. open(str(chat_id) + "/data/limit.txt", "w").write("750")
  170. if os.path.isfile(str(chat_id) + "/data/8ball.txt") == False:
  171. open(str(chat_id) + "/data/8ball.txt", "w").write("False")
  172. if os.path.isfile(str(chat_id) + "/data/arabic.txt") == False:
  173. open(str(chat_id) + "/data/arabic.txt", "w").write("True")
  174. if os.path.isfile(str(chat_id) + "/data/leaderboard.txt") == False:
  175. open(str(chat_id) + "/data/leaderboard.txt", "w").write("True")
  176. if os.path.isfile(str(chat_id) + "/data/scramble.txt") == False:
  177. open(str(chat_id) + "/data/scramble.txt", "w").write('False')
  178. if os.path.isfile(
  179. str(chat_id) + "/data/type.txt") == False:
  180. open(
  181. str(chat_id) + "/data/type.txt", "w").write('False')
  182. if os.path.isfile(str(chat_id) + "/data/spam.txt") == False:
  183. open(str(chat_id) + "/data/spam.txt", "w").write('True')
  184. if os.path.isfile(str(chat_id) + "/data/roll.txt") == False:
  185. open(str(chat_id) + "/data/roll.txt", "w").write("False")
  186. if os.path.isfile(str(chat_id) + "/data/blacklisted.txt") == False:
  187. open(str(chat_id) + "/data/blacklisted.txt", "w").write("")
  188. if os.path.isfile(str(chat_id) + "/data/link.txt") == False:
  189. open(str(chat_id) + "/data/link.txt", "w").write("True")
  190. if os.path.isfile(str(chat_id) + "/data/temp.txt") == False:
  191. open(str(chat_id) + "/data/temp.txt", "w")
  192. if os.path.isfile(str(chat_id) + "/data/lock.txt") == False:
  193. open(str(chat_id) + "/data/lock.txt", "w").write("False")
  194. if os.path.isfile(str(chat_id) + "/data/game.txt") == False:
  195. open(str(chat_id) + "/data/game.txt", "w").write("True")
  196. if os.path.isfile(str(chat_id) + "/data/state.txt") == False:
  197. open(str(chat_id) + "/data/state.txt", "w").write('False')
  198. if os.path.isfile(str(chat_id) + "/data/pong.txt") == False:
  199. open(str(chat_id) + "/data/pong.txt", "w").write("False")
  200. if os.path.isfile(str(chat_id) + "/data/mm.txt") == False:
  201. open(str(chat_id) + "/data/mm.txt", "w").write("False")
  202. if os.path.isfile(str(chat_id) + "/data/games.txt") == False:
  203. open(str(chat_id) + "/data/games.txt", "w").write("False")
  204. if os.path.isfile(str(chat_id) + "/data/antibot.txt") == False:
  205. open(str(chat_id) + "/data/antibot.txt", "w").write("False")
  206. if os.path.isfile(str(chat_id) + "/data/urban.txt") == False:
  207. open(str(chat_id) + "/data/urban.txt", "w").write("False")
  208. if os.path.isfile(str(chat_id) + "/data/flip.txt") == False:
  209. open(str(chat_id) + "/data/flip.txt", "w").write("False")
  210. if os.path.isfile(str(chat_id) + "/data/blacklist.txt") == False:
  211. open(str(chat_id) + "/data/blacklist.txt", "w")
  212. if os.path.isfile(str(chat_id) + "/data/blacklistusername.txt") == False:
  213. open(str(chat_id) + "/data/blacklistusername.txt", "w")
  214. if os.path.isfile(str(chat_id) + "/data/wel.txt") == False:
  215. open(str(chat_id) + "/data/wel.txt", "w").write("True")
  216. if os.path.isfile(str(chat_id) + "/data/photo.txt") == False:
  217. open(str(chat_id) + "/data/photo.txt", "w").write("True")
  218. if os.path.isfile(str(chat_id) + "/data/admin.txt") == False:
  219. open(str(chat_id) + "/data/admin.txt", "w")
  220. if os.path.isfile(str(chat_id) + "/data/remind.txt") == False:
  221. open(str(chat_id) + "/data/remind.txt", "w").write("False")
  222. if os.path.isfile(str(chat_id) + "/data/tts.txt") == False:
  223. open(str(chat_id) + "/data/tts.txt", "w").write("False")
  224. if os.path.isfile(str(chat_id) + "/wel.txt") == False:
  225. if messageType != 'private':
  226. open(str(chat_id) + "/wel.txt", "w").write("True")
  227. if os.path.isfile(str("data/locked" + str(messageFromID) + ".txt")) == False:
  228. open(str("data/locked" + str(messageFromID) + ".txt"), "w").write("False")
  229. #DEFINE MESSAGES
  230. if os.path.isfile(str(chat_id) + "/data/photo.txt") == False:
  231. open(str(chat_id) + "/data/photo.txt", "w").write("True")
  232. if os.path.isfile(str(chat_id) + "/data/8ball.txt") == False:
  233. open(str(chat_id) + "/data/8ball.txt", "w").write("True")
  234. if 'caption' in msg:
  235. caption = str(msg['caption'])
  236. else:
  237. caption = None
  238.  
  239. def newCap():
  240. if messageType != 'private':
  241. if os.path.isfile("rooms/" + str(messageFromID) + "wins.txt") == False:
  242. open("rooms/" + str(messageFromID) + "wins.txt", "w").write("0")
  243. if os.path.isfile("rooms/" + str(messageFromID) + "money.txt") == False:
  244. open("rooms/" + str(messageFromID) + "money.txt", "w").write("0")
  245. if os.path.isfile(str(chat_id) + "/messagecount.txt") == False:
  246. open(str(chat_id) + "/messagecount.txt", "w").write("1")
  247. else:
  248. try:
  249. minus = int(str(open(str(chat_id) + "/messagecount.txt", "r+").readlines()).replace("[", "").replace("'", "").replace("]", "")) + 1
  250. open(str(chat_id) + "/messagecount.txt", "w").write(str(minus))
  251. except:
  252. open(str(chat_id) + "/messagecount.txt", "w").write('1')
  253. if 'username' in msg['from']:
  254. USER = "\n[" + str(msg['from']['username']) + "](t.me/" + str(msg['from']['username']) + ")"
  255. else:
  256. USER = "\n" + str(msg['from']['first_name'])
  257. with open(str(chat_id) + "/data/numberone.txt", "r") as one:
  258. for _ in range(3):
  259. numberone = one.readline()
  260. with open(str(chat_id) + "/data/numbertwo.txt", "r") as two:
  261. for _ in range(3):
  262. numbertwo = two.readline()
  263. with open(str(chat_id) + "/data/numberthree.txt", "r") as three:
  264. for _ in range(3):
  265. numberthree = three.readline()
  266.  
  267. if os.path.isfile(
  268. str(chat_id) +
  269. '/messages/' + str(messageFromID) + ".txt") == False:
  270. open(
  271. str(chat_id) +
  272. "/messages/" + str(messageFromID) + ".txt", "w").write("1")
  273. if int(str(open(
  274. str(chat_id) +
  275. "/messages/" + str(messageFromID) + ".txt", "r").read())) > int(str(numberone)):
  276. open(str(chat_id) + "/data/numberone.txt", "w").write(str(msg['from']['id']) + USER + "\n" + str(open(
  277. str(chat_id) +
  278. "/messages/" + str(messageFromID) + ".txt", "r").read()))
  279. if int(str(open("rooms/" + str(messageFromID) + "money.txt", "r").read())) > int(str(numbertwo)):
  280. open(str(chat_id) + "/data/numbertwo.txt", "w").write(str(msg['from']['id']) + USER + "\n" + str(open(
  281. "rooms/" + str(messageFromID) + "money.txt", "r").read()))
  282. if int(str(open(
  283. "rooms/" + str(messageFromID) + "wins.txt", "r").read())) > int(str(numberthree)):
  284. open(str(chat_id) + "/data/numberthree.txt", "w").write(str(msg['from']['id']) + USER + "\n" + str(open("rooms/" + str(messageFromID) + "wins.txt", "r").read()))
  285.  
  286. else:
  287. with open(str(chat_id) + "/data/numberone.txt", "r") as one:
  288. for _ in range(3):
  289. numberone = one.readline()
  290. with open(str(chat_id) + "/data/numbertwo.txt", "r") as two:
  291. for _ in range(3):
  292. numbertwo = two.readline()
  293. with open(str(chat_id) + "/data/numberthree.txt", "r") as three:
  294. for _ in range(3):
  295. numberthree = three.readline()
  296. try:
  297. minus = int(
  298. str(open(
  299. str(chat_id) +
  300. "/messages/" + str(messageFromID) + ".txt", "r+").readlines()).replace("[", "").replace(
  301. "'", "").replace("]", "")) + 1
  302. open(
  303. str(chat_id) +
  304. "/messages/" + str(messageFromID) + ".txt", "w").write(str(minus))
  305. except:
  306. open(
  307. str(chat_id) +
  308. "/messages/" + str(messageFromID) + ".txt", "w").write('1')
  309. try:
  310. if int(str(open(
  311. str(chat_id) +
  312. "/messages/" + str(messageFromID) + ".txt", "r").read())) > int(str(numberone)):
  313. open(str(chat_id) + "/data/numberone.txt", "w").write(str(msg['from']['id']) + USER + "\n" + str(open(
  314. str(chat_id) +
  315. "/messages/" + str(messageFromID) + ".txt", "r").read()))
  316. except:
  317. open(
  318. str(chat_id) +
  319. "/messages/" + str(messageFromID) + ".txt", "w").write('2')
  320. if int(str(open("rooms/" + str(messageFromID) + "money.txt", "r").read())) > int(str(numbertwo)):
  321. open(str(chat_id) + "/data/numbertwo.txt", "w").write(str(msg['from']['id']) + USER + "\n" + str(open(
  322. "rooms/" + str(messageFromID) + "money.txt", "r").read()))
  323. if int(str(open(
  324. "rooms/" + str(messageFromID) + "wins.txt", "r").read())) > int(str(numberthree)):
  325. open(str(chat_id) + "/data/numberthree.txt", "w").write(str(msg['from']['id']) + USER + "\n" + str(open("rooms/" + str(messageFromID) + "wins.txt", "r").read()))
  326. if isPrivateMessage == False:
  327. print(msg['chat']['title'], ', ', msg['from']['first_name'], ':\n', msg['text'])
  328. else:
  329. print('Private Message, ', msg['from']['first_name'], ':\n', msg['text'])
  330. if 'text' in msg:
  331. t = threading.Thread(target=newCap)
  332. t.start()
  333. message = msg['text'].lower()
  334. else:
  335. if 'caption' in msg:
  336. message = msg['caption'].lower()
  337. else:
  338. message = ''
  339. if '/debug' in message:
  340. if str(msg['from']['id']) == str('374986841'):
  341. if '353129131' in str(open('token.dat', 'r').read()):
  342. if "True" in open("data/debug.txt", "r"):
  343. open("data/debug.txt", "w").write("False")
  344. bot.sendMessage(str(-1001347177423), "Debug mode off. I will now reply.")
  345. else:
  346. open("data/debug.txt", "w").write("True")
  347. bot.sendMessage(str(-1001347177423), "Debug mode on. I will no longer reply.")
  348.  
  349. def replace_line(file_name, line_num, text):
  350. lines = open(file_name, 'r').readlines()
  351. lines[line_num] = text
  352. out = open(file_name, 'w')
  353. out.writelines(lines)
  354. out.close()
  355. def gettime():
  356. tf = timezonefinder.TimezoneFinder()
  357. saidlocation = str(msg['text'])[6:]
  358.  
  359. geo_keys = ['AIzaSyC9CNdTPQGkmm2Wq6e3e-DnC96lNTsdp8s']
  360. geolocator = geocoders.GoogleV3(api_key=random.choice(geo_keys))
  361.  
  362. place, (lat, lng) = geolocator.geocode(saidlocation)
  363.  
  364. timezone_str = tf.certain_timezone_at(lat=lat, lng=lng)
  365. timezone_str = tf.certain_timezone_at(lat=lat, lng=lng)
  366.  
  367. if timezone_str is None:
  368. print('Nah')
  369. else:
  370. timeZone = pytz.timezone(timezone_str)
  371. dt = datetime.datetime.utcnow()
  372. location = timezone(str(timezone_str))
  373. location_time = datetime.datetime.now(location)
  374. print(location_time.strftime('It is currently %I:%M %p in ' + saidlocation + '.'))
  375. bot.sendMessage(chat_id, location_time.strftime('It is currently %I:%M %p in ' + saidlocation.title() + '.'))
  376. if '/time ' in message:
  377. t = threading.Thread(target=gettime)
  378. t.start()
  379.  
  380. def getLastLines(path, n):
  381. # return the las N lines from the file indicated in path
  382.  
  383. fp = open(path)
  384. for i in range(n):
  385. line = fp.readline()
  386. if line == '':
  387. return []
  388.  
  389. back = open(path)
  390. for each in fp:
  391. back.readline()
  392.  
  393. result = []
  394. for line in back:
  395. result.append(line[:-1])
  396.  
  397. return result
  398.  
  399. def spamDetection():
  400. endTime = datetime.datetime.now() + datetime.timedelta(
  401. seconds=5)
  402. while True:
  403. if datetime.datetime.now() >= endTime:
  404. os.remove(str(chat_id) + "/messages/" + str(msg['from']['id']) + 'spam.dat')
  405. os.remove(str(chat_id) + "/messages/" + str(msg['from']['id']) + 'cache.dat')
  406. break
  407. if "5" in str(open(str(chat_id) + "/messages/" + str(msg['from']['id']) + "spam.dat", "r").read()):
  408. if "True" in open(str(chat_id) + "/data/spam.txt", "r"):
  409. os.remove(str(chat_id) + "/messages/" + str(msg['from']['id']) + 'spam.dat')
  410. bot.restrictChatMember(chat_id, msg['from']['id'], can_send_messages=False,
  411. can_add_web_page_previews=False, can_send_media_messages=False,
  412. can_send_other_messages=False)
  413. print('MUTED USER FOR SPAM')
  414. bot.sendMessage(chat_id, usersName + " has been muted for spamming. (Use /spam to turn off)", reply_to_message_id=msg['message_id'])
  415. messageOne = str(open(str(chat_id) + "/messages/" + 'msgid' + str(msg['from']['id']) + ".dat", "r").readlines()[0])
  416. lastestMessages = getLastLines(str(chat_id) + "/messages/" + 'msgid' + str(msg['from']['id']) + ".dat", 12)
  417. for line in lastestMessages:
  418. try:
  419. telegram.Bot.deleteMessage(self=Bot, chat_id=chat_id, message_id=line)
  420. except:
  421. pass
  422. break
  423. else:
  424. os.remove(str(chat_id) + "/messages/" + str(msg['from']['id']) + 'spam.dat')
  425. os.remove(str(chat_id) + "/messages/" + str(msg['from']['id']) + 'cache.dat')
  426.  
  427. def getMessage():
  428.  
  429. if os.path.isfile(str(chat_id) + '/messages/msgid' + str(msg['from']['id']) + '.dat') == False:
  430. open(str(chat_id) + '/messages/msgid' + str(msg['from']['id']) + '.dat', 'w').write(
  431. str(msg['message_id']) + '\n')
  432. else:
  433. open(str(chat_id) + '/messages/msgid' + str(msg['from']['id']) + '.dat', 'a+').write(
  434. str(msg['message_id']) + '\n')
  435. if str(messageFromID) in open(str(chat_id) + "/data/admin.txt", "r").read():
  436. pass
  437. else:
  438. if startSpam == True:
  439. if 'photo' in msg:
  440. if 'caption' in msg:
  441. if msg['caption'] == "":
  442. pass
  443. else:
  444. if os.path.isfile(str(chat_id) + "/messages/" + str(msg['from']['id']) + "spam.dat") == False:
  445. # open(str(chat_id) + "/messages/" + str(msg['from']['id']) + "spam.dat", "w").write("1")
  446.  
  447. # open(str(chat_id) + "/messages/" + str(msg['from']['id']) + "cache.dat", "w").write(
  448. # str(msg['message_id']) + '\n')
  449. # t = threading.Thread(target=spamDetection)
  450. # t.start()
  451. pass
  452. else:
  453. if '1' in open(str(chat_id) + "/messages/" + str(msg['from']['id']) + "spam.dat", "r").read():
  454. open(str(chat_id) + "/messages/" + str(msg['from']['id']) + "spam.dat", "w").write("2")
  455.  
  456. open(str(chat_id) + "/messages/" + str(msg['from']['id']) + "cache.dat", "a+").write(
  457. str(msg['message_id']) + '\n')
  458.  
  459. elif '2' in open(str(chat_id) + "/messages/" + str(msg['from']['id']) + "spam.dat", "r").read():
  460. open(str(chat_id) + "/messages/" + str(msg['from']['id']) + "spam.dat", "w").write("3")
  461. open(str(chat_id) + "/messages/" + str(msg['from']['id']) + "cache.dat", "a+").write(
  462. str(msg['message_id']) + '\n')
  463.  
  464. elif '3' in open(str(chat_id) + "/messages/" + str(msg['from']['id']) + "spam.dat", "r").read():
  465. open(str(chat_id) + "/messages/" + str(msg['from']['id']) + "spam.dat", "w").write("4")
  466. open(str(chat_id) + "/messages/" + str(msg['from']['id']) + "cache.dat", "a+").write(
  467. str(msg['message_id']) + '\n')
  468.  
  469. elif '4' in open(str(chat_id) + "/messages/" + str(msg['from']['id']) + "spam.dat", "r").read():
  470. open(str(chat_id) + "/messages/" + str(msg['from']['id']) + "spam.dat", "w").write("5")
  471. open(str(chat_id) + "/messages/" + str(msg['from']['id']) + "cache.dat", "a+").write(
  472. str(msg['message_id']) + '\n')
  473. if msg:
  474. if isPrivateMessage == False:
  475. t = threading.Thread(target=getMessage)
  476. t.start()
  477.  
  478. if isPrivateMessage == True:
  479. if '/kickme' in msg['text']:
  480. contents = '*Kick me*\n\nWith this command, you can leave a group with a single command. This only kicks, so you can join back.'
  481. if 'Universal commands' in msg['text']:
  482. print('S')
  483. else:
  484. if 'help' in message:
  485. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  486. else:
  487. if isPrivateMessage == True:
  488. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  489. if '/scramble' in msg['text']:
  490. contents = '*Scramble*\n\nThis is a fun game where you unscramble words with friends, and try to be the first one to win. Depending on how hard the words are, you get a different amount of coins each time. Default time limit is 30 seconds, but this can be changed with /limit.'
  491. if 'Universal commands' in msg['text']:
  492. print('S')
  493. else:
  494. if 'help' in message:
  495. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  496. else:
  497. if isPrivateMessage == True:
  498. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  499. if '/unban' in msg['text']:
  500. contents = '*Unbanning users*\n\nEasily unban users with this command, by replying or "/ban @username."\n\n_/unban @USER\n/unban (REPLIED)_'
  501. if 'Universal commands' in msg['text']:
  502. print('S')
  503. else:
  504. if 'help' in message:
  505. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  506. else:
  507. if isPrivateMessage == True:
  508. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  509. if '/mute' in msg['text']:
  510. contents = '*Muting users*\n\nYou can mute users from talking in a group chat. With this, they can still read the chat.\n\n_/mute @USER\n/mute (REPLIED)_'
  511. if 'Universal commands' in msg['text']:
  512. print('S')
  513. else:
  514. if 'help' in message:
  515. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  516. else:
  517. if isPrivateMessage == True:
  518. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  519. if '/delcom' in msg['text']:
  520. contents = '*Deleting commands*\n\nThis command is used to delete existing commands. All you have to do is use "/delcom /hug" and thats it.\n\n_/delcom <command name>_'
  521. if 'Universal commands' in msg['text']:
  522. print('S')
  523. else:
  524. if 'help' in message:
  525. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  526. else:
  527. if isPrivateMessage == True:
  528. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  529. if '/photo' in msg['text']:
  530. contents = '*Toggling photo editing*\n\nUse this to turn on and off the photo editing feature.'
  531. if 'Universal commands' in msg['text']:
  532. print('S')
  533. else:
  534. if 'help' in message:
  535. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  536. else:
  537. if isPrivateMessage == True:
  538. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  539. if '/voice' in msg['text']:
  540. contents = '*Toggling text to speech*\n\nThis command toggles the ability to use the text to speech command (/tts)'
  541. if 'Universal commands' in msg['text']:
  542. print('S')
  543. else:
  544. if 'help' in message:
  545. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  546. else:
  547. if isPrivateMessage == True:
  548. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  549. if '/arabic' in msg['text']:
  550. contents = '*Toggling arabic text*\n\nA lot of times, arabic is used to spam chats, so this helps prevent this. Use /arabic to toggle the auto-delete arabic feature. Whenever anyone send arabic characters, the message will be deleted.'
  551. if 'Universal commands' in msg['text']:
  552. print('S')
  553. else:
  554. if 'help' in message:
  555. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  556. else:
  557. if isPrivateMessage == True:
  558. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  559. if '/blacklist' in msg['text']:
  560. contents = '*Blacklisting phrases*\n\nThis command is used for blacklisting certain phrases. To use this, you use "/blacklist <phrase to be blacklisted" and whenever this is used, the message is deleted and the user is kicked.'
  561. if 'Universal commands' in msg['text']:
  562. print('S')
  563. else:
  564. if 'help' in message:
  565. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  566. else:
  567. if isPrivateMessage == True:
  568. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  569. if '/nomedia' in msg['text']:
  570. contents = '*Restricting media messages*\n\nRestrict a users ablity to send media messages like images, gifs, voice messages, files, or stickers.'
  571. if 'Universal commands' in msg['text']:
  572. print('S')
  573. else:
  574. if 'help' in message:
  575. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  576. else:
  577. if isPrivateMessage == True:
  578. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  579. if '/lock' in msg['text']:
  580. contents = '*Locking your groupchat*\n\nWith this, you can lock and unlock your group chat. Everytime someone tries to join, they get kicked. Use this to toggle on and off.'
  581. if 'Universal commands' in msg['text']:
  582. print('S')
  583. else:
  584. if 'help' in message:
  585. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  586. else:
  587. if isPrivateMessage == True:
  588. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  589. if '/gt' in msg['text']:
  590. contents = '*Games toggle*\n\nTurn games on and off with this command.'
  591. if 'Universal commands' in msg['text']:
  592. print('S')
  593. else:
  594. if 'help' in message:
  595. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  596. else:
  597. if isPrivateMessage == True:
  598. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  599. if '/eb' in msg['text']:
  600. contents = '*Toggle 8ball questions*\n\nTurn /8ball messages on and off.'
  601. if 'Universal commands' in msg['text']:
  602. print('S')
  603. else:
  604. if 'help' in message:
  605. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  606. else:
  607. if isPrivateMessage == True:
  608. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  609. if '/antibot' in msg['text']:
  610. contents = '*Restricting bots from your group*\n\nToggle this to either restrict users from adding bots, or not.'
  611. if 'Universal commands' in msg['text']:
  612. print('S')
  613. else:
  614. if 'help' in message:
  615. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  616. else:
  617. if isPrivateMessage == True:
  618. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  619. if '/jt' in msg['text']:
  620. contents = '*Toggling jokes*\n\nUse this to disable the joke feature (/jokes).'
  621. if 'Universal commands' in msg['text']:
  622. print('S')
  623. else:
  624. if 'help' in message:
  625. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  626. else:
  627. if isPrivateMessage == True:
  628. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  629. if '/roll' in msg['text']:
  630. if 'help' in msg['text']:
  631. if 'roll2' in msg['text']:
  632. contents = '*Rolling two dice*\n\nRoll two dice with this command.'
  633. if 'Universal commands' in msg['text']:
  634. print('S')
  635. else:
  636. if 'help' in message:
  637. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  638. else:
  639. if isPrivateMessage == True:
  640. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  641. else:
  642. contents = '*Rolling a single die*\n\nRoll a single die with this command.'
  643. if 'Universal commands' in msg['text']:
  644. print('S')
  645. else:
  646. if 'help' in message:
  647. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  648. else:
  649. if isPrivateMessage == True:
  650. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  651. else:
  652. pass
  653. if '/bw' in msg['text']:
  654. if 'reply_to_message' in msg:
  655. contents = '*Making an image black and white*\n\nThis make the selected image black and white.\n\n_/bw (REPLIED)_'
  656. if 'Universal commands' in msg['text']:
  657. print('S')
  658. else:
  659. if 'help' in message:
  660. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  661. else:
  662. if isPrivateMessage == True:
  663. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  664. else:
  665. if 'help' in msg['text']:
  666. contents = '*Making an image black and white*\n\nThis make the selected image black and white.\n\n_/bw (REPLIED)_'
  667. if 'Universal commands' in msg['text']:
  668. print('S')
  669. else:
  670. if 'help' in message:
  671. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  672. else:
  673. if isPrivateMessage == True:
  674. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  675. else:
  676. contents = '*Making an image black and white*\n\nThis make the selected image black and white.\n\n_/bw (REPLIED)_'
  677. if 'Universal commands' in msg['text']:
  678. print('S')
  679. else:
  680. if 'help' in message:
  681. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  682. else:
  683. if isPrivateMessage == True:
  684. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  685. if '/swirl' in msg['text']:
  686. if 'reply_to_message' in msg:
  687. contents = '*Swirling an image*\n\nThis make the selected image swirled.\n\n_/swirl (REPLIED)_'
  688. if 'Universal commands' in msg['text']:
  689. print('S')
  690. else:
  691. if 'help' in message:
  692. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  693. else:
  694. if isPrivateMessage == True:
  695. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  696. else:
  697. if 'help' in msg['text']:
  698.  
  699. contents = '*Swirling an image*\n\nThis make the selected image swirled.\n\n_/swirl (REPLIED)_'
  700. if 'Universal commands' in msg['text']:
  701. print('S')
  702. else:
  703. if 'help' in message:
  704. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  705. else:
  706. if isPrivateMessage == True:
  707. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  708. else:
  709.  
  710. contents = '*Swirling an image*\n\nThis make the selected image swirled.\n\n_/swirl (REPLIED)_'
  711. if 'Universal commands' in msg['text']:
  712. print('S')
  713. else:
  714. if 'help' in message:
  715. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  716. else:
  717. if isPrivateMessage == True:
  718. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  719. if '/rt' in msg['text']:
  720. contents = '*Toggling rolling dice*\n\nToggle the /roll and /roll2 feature_.'
  721. if 'Universal commands' in msg['text']:
  722. print('S')
  723. else:
  724. if 'help' in message:
  725. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  726. else:
  727. if isPrivateMessage == True:
  728. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  729. if '/pin' in msg['text']:
  730. contents = '*Pinning messages*\n\nReply to any message to pin it in the group.\n\n_/pin (REPLIED)'
  731. if 'Universal commands' in msg['text']:
  732. print('S')
  733. else:
  734. if 'help' in message:
  735. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  736. else:
  737. if isPrivateMessage == True:
  738. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  739. if '/color' in msg['text']:
  740. contents = '*Changing welcome message color*\n\nUse this to change the welcome greet pictures color. Use /color <color name>\n\nExample:\n\n/color pink\n\n_User Joined:_'
  741. if 'Universal commands' in msg['text']:
  742. print('S')
  743. else:
  744. if 'help' in message:
  745. filename = 'colorexamp.jpg'
  746. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  747.  
  748. bot.sendPhoto(chat_id, open(filename, "rb"))
  749. else:
  750. if isPrivateMessage == True:
  751. filename = 'colorexamp.jpg'
  752. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  753.  
  754. bot.sendPhoto(chat_id, open(filename, "rb"))
  755. if '/colour' in msg['text']:
  756. contents = '*Changing welcome message colour*\n\nUse this to change the welcome greet pictures colour. Use /colour <colour name>\n\nExample:\n\n/colour pink\n\n_User Joined:_'
  757. if 'Universal commands' in msg['text']:
  758. print('S')
  759. else:
  760. if 'help' in message:
  761. filename = 'colorexamp.jpg'
  762. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  763.  
  764. bot.sendPhoto(chat_id, open(filename, "rb"))
  765. else:
  766. if isPrivateMessage == True:
  767. filename = 'colorexamp.jpg'
  768. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  769.  
  770. bot.sendPhoto(chat_id, open(filename, "rb"))
  771. if '/greet' in msg['text']:
  772. contents = '*Changing greeting message type*\n\nUse this to toggle between a text welcome message and a picture welcome message. Default is text. Use /wel with photo greeting on, and change the text that says "Welcome" to your choice! Or change the color with /color'
  773. if 'Universal commands' in msg['text']:
  774. print('S')
  775. else:
  776. if 'help' in message:
  777. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  778. else:
  779. if isPrivateMessage == True:
  780. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  781. if '/title' in msg['text']:
  782. contents = '*Change the title of the group*\n\nUse this command to change the title of your groupchat.\n\n_/title <new title of chat>_'
  783. if 'Universal commands' in msg['text']:
  784. print('S')
  785. else:
  786. if 'help' in message:
  787. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  788. else:
  789. if isPrivateMessage == True:
  790. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  791. if '/limit' in msg['text']:
  792. contents = '*Changing the game time limit*\n\nThis command gives you the ablility to change how long each scramble game lasts. This is in seconds.\n\n_/limit <time in seconds>_'
  793. if 'Universal commands' in msg['text']:
  794. print('S')
  795. else:
  796. if 'help' in message:
  797. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  798. else:
  799. if isPrivateMessage == True:
  800. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  801. if '/promote' in msg['text']:
  802. contents = '*Promoting users in your group*\n\nThis command lets your promote users to be admin of the bot, but not the actually group. What this means is that the user can user commands like /kick or /ban on the bot, but they would not be an actual admin.\n\n_/promote @USER\n/promote (REPLIED)_'
  803. if 'Universal commands' in msg['text']:
  804. print('S')
  805. else:
  806. if 'help' in message:
  807. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  808. else:
  809. if isPrivateMessage == True:
  810. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  811. if '/warn' in msg['text']:
  812. contents = '*Warning users*\n\nIf a user did something bad, and you want to give them a few chances, you can warn them. Everyone get 3 warns, then you are kicked. View your warns on /me, reset someones warns with /reset.\n\n_/warn @USER\n/warn (REPLIED)\n/reset @USER\n/warn (REPLIED)_'
  813. if 'Universal commands' in msg['text']:
  814. print('S')
  815. else:
  816. if 'help' in message:
  817. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  818. else:
  819. if isPrivateMessage == True:
  820. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  821. if '/reset' in msg['text']:
  822. contents = '*Resetting someones warns*\n\nReset a users warn count.\n\n_/reset @USER\n/reset (REPLIED)_'
  823. if 'Universal commands' in msg['text']:
  824. print('S')
  825. else:
  826. if 'help' in message:
  827. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  828. else:
  829. if isPrivateMessage == True:
  830. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  831. if '/demote' in msg['text']:
  832. contents = '*Demoting users in your group*\n\nThis command lets your demotes users and takes their admin away (no group admin).\n\n_/demote @USER\n/demote (REPLIED)_'
  833. if 'Universal commands' in msg['text']:
  834. print('S')
  835. else:
  836. if 'help' in message:
  837. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  838. else:
  839. if isPrivateMessage == True:
  840. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  841. if '/toggles' in msg['text']:
  842. contents = '*View your toggles*\n\nView what features are on and off.\n\n' + """Example:\n_Jokes: Off
  843. Magic 8Ball: On
  844. Rolling: Off
  845. Invite Links: On
  846. Group Lock: Off
  847. Antibot: On
  848. Photo edit: On
  849. Urban Dict: On
  850. TTS: On_"""
  851. if 'Universal commands' in msg['text']:
  852. print('S')
  853. else:
  854. if 'help' in message:
  855. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  856. else:
  857. if isPrivateMessage == True:
  858. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  859. if '/unrestrict' in msg['text']:
  860. contents = '*Unrestricting users*\n\nThis command is used to unrestrict users and giving them all chat permissions (sending messages, photos, gifs, etc)\n\n_/unrestrict @USER\n/unrestrict (REPLIED)_'
  861. if 'Universal commands' in msg['text']:
  862. print('S')
  863. else:
  864. if 'help' in message:
  865. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  866. else:
  867. if isPrivateMessage == True:
  868. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  869. if '/addcom' in msg['text']:
  870. contents = "*Adding custom commands*\n\nIf you want a command like /slap, or simply a counter for how many times someone gets banned, you can use this to satisfy your needs. This command allows you to add your own commands and have it respond in a certain way when it hears a phrase. For example, if you wanted a hug command you would make it like this (NOTE: You do not need to use a slash, it can be any phrase):\n\n/addcom /hug::$rn has been hugged by $n!\n\nThe $rn symbolizes the name of the person you are replying to. The $n is the one who sends the message.\n\n*Adding a counter*\n\nTo add a counter, you can do this\n\n/addcom /score::The current score is $c!\n\nThe $c is updated by one everytime the command is used."
  871. if 'Universal commands' in msg['text']:
  872. pass
  873. else:
  874. if 'help' in message:
  875. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  876. bot.sendMessage(chat_id, '\n\n*More customs:*\n$rn - Replied users name\n$n - Senders name\n$u - Senders username\n$ru - Replied users username.\n$c - Counter (Goes up by 1 each time it is used)\n$admin - Add this anywhere after the ::, it will make it an admin only command.', parse_mode='markdown')
  877. else:
  878. if isPrivateMessage == True:
  879. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  880.  
  881. bot.sendMessage(chat_id,
  882. '*More customs:*\n$rn - Replied users name\n$n - Senders name\n$u - Senders username\n$ru - Replied users username.\n$c - Counter (Goes up by 1 each time it is used)\n$admin - Add this anywhere after the ::, it will make it an admin only command.',
  883. parse_mode='markdown')
  884. if '/unmute' in msg['text']:
  885. contents = '*Unmuting users*\n\nIf a user has previously been muted, they can be unmuted with this.\n\n_/unmute @USER\n/unmute (REPLIED)_'
  886. if 'Universal commands' in msg['text']:
  887. print('S')
  888. else:
  889. if 'help' in message:
  890. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  891. else:
  892. if isPrivateMessage == True:
  893. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  894. if '/link' in msg['text']:
  895. contents = '*Restricting links*\n\nWith this command, you can restrict your users from sending invite links. If one is sent, it will be deleted. Admins still have the ability to send links.'
  896. if 'Universal commands' in msg['text']:
  897. print('S')
  898. else:
  899. if 'help' in message:
  900. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  901. else:
  902. if isPrivateMessage == True:
  903. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  904. if '/ban' in msg['text']:
  905. contents = '*Banning users*\n\nThis allows you to reply to someones message (or /ban @username), and remove them from the group. They cannot join back unless they are unbanned (see /unban).\n\n_/ban @USER\n/ban (REPLIED)_'
  906. if 'Universal commands' in msg['text']:
  907. print('S')
  908. else:
  909. if 'help' in message:
  910. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  911. else:
  912. if isPrivateMessage == True:
  913. bot.sendMessage(chat_id, contents, parse_mode='markdown')
  914.  
  915. if '/kick' in msg['text']:
  916. if 'kickme' not in msg['text']:
  917. if 'Universal commands' in msg['text']:
  918. print('S')
  919. else:
  920. if 'help' in message:
  921. bot.sendMessage(chat_id, '*Kicking users*\n\nThis allows you to reply to someones message (or /kick @username), and remove them from the group. They can join back as soon as possible.\n\n_/kick @USER\n/kick (REPLIED)_', parse_mode='markdown')
  922. else:
  923. if isPrivateMessage == True:
  924. bot.sendMessage(chat_id, '*Kicking Users*\n\nThis allows you to reply to someones message (or /kick @username), and remove them from the group. They can join back as soon as possible. \n\n_/kick @USER\n/kick (REPLIED)_', parse_mode='markdown')
  925. def catchuser():
  926. if str(msg['from']['id']) in str(open("data/listofusers.data", "r").read()):
  927. with open("data/listofusers.data", 'r') as f:
  928. lines = f.read().split("\n")
  929.  
  930. # print("Number of lines is {}".format(len(lines)))
  931.  
  932. word = str(msg['from']['id']) # dummy word. you take it from input
  933.  
  934. # iterate over lines, and print out line numbers which contain
  935. # the word of interest.
  936. for i, line in enumerate(lines):
  937. if word in line: # or word in line.split() to search for full words
  938. # print("Word \"{}\" found in line {}".format(word, i + 1))
  939. foundLine = i
  940. if 'username' in msg['from']:
  941. adminUser = str(msg['from']['username'])
  942. else:
  943. adminUser = "var?empty"
  944. replace_line("data/listofusers.data", i, str(msg['from']['id']) + '>:>' + adminUser + '\n')
  945. else:
  946. if 'username' in msg['from']:
  947. usernameGet = str(msg['from']['username'])
  948. else:
  949. usernameGet = 'var?empty'
  950. open("data/listofusers.data", "a").write(str(msg['from']['id']) + '>:>' + usernameGet.lower() +'\n')
  951.  
  952.  
  953.  
  954. def idktbh():
  955. if str(msg['chat']['id']) in str(open("data/listofgroups.data", "r").read()):
  956. ()
  957. else:
  958. open("data/listofgroups.data", "a").write(str(msg['chat']['id']) + '\n')
  959.  
  960. if isPrivateMessage == False:
  961. t = threading.Thread(target=idktbh)
  962. t.start()
  963.  
  964. def catchadmin():
  965. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  966. if bot.getChatMember(chat_id, msg['from']['id']) in bot.getChatAdministrators(chat_id):
  967. adminStatus = True
  968. elif str(msg['from']['id']) in open(str(chat_id) + '/data/admin.txt', 'r').read():
  969. adminStatus = True
  970. else:
  971. #bad_words = [str(msg['from']['id'])]
  972. #with open(chat_id + '/data/adminlist.data', 'r') as oldfile, open(chat_id + '/data/adminlist.data', 'w') as newfile:
  973. # for line in oldfile:
  974. # if not any(bad_word in line for bad_word in bad_words):
  975. # newfile.write(line)
  976. fn = str(msg['chat']['id']) + '/data/adminlist.data'
  977. f = open(fn)
  978. output = []
  979. for line in f:
  980. if str(msg['from']['id']) != line.strip():
  981. output.append(line)
  982. f.close()
  983. f = open(fn, 'w')
  984. f.writelines(output)
  985. f.close()
  986. else:
  987. if bot.getChatMember(chat_id, messageFromID) in bot.getChatAdministrators(chat_id):
  988. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "rb"):
  989. pass
  990. else:
  991. with open(chat_id + "/data/adminlist.data", 'r') as f:
  992. lines = f.read().split("\n")
  993.  
  994. # print("Number of lines is {}".format(len(lines)))
  995.  
  996. word = str(msg['from']['id']) # dummy word. you take it from input
  997.  
  998. # iterate over lines, and print out line numbers which contain
  999. # the word of interest.
  1000. for i, line in enumerate(lines):
  1001. if word in line: # or word in line.split() to search for full words
  1002. #print("Word \"{}\" found in line {}".format(word, i + 1))
  1003. print(i)
  1004. if 'username' in msg['from']:
  1005. adminUser = str(msg['from']['username'])
  1006. else:
  1007. adminUser = "var?empty"
  1008. replace_line(str(chat_id) + '/data/adminlist.data', i, str(msg['from']['id']) + '\n')
  1009.  
  1010. else:
  1011. if 'username' in msg['from']:
  1012. adminUser = str(msg['from']['username'])
  1013. else:
  1014. adminUser = "var?empty"
  1015. open(chat_id + "/data/adminlist.data", "a").write(str(msg['from']['id']) + '\n')
  1016.  
  1017. if str(messageFromID) in open(str(chat_id) + "/data/admin.txt", "r").read():
  1018. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "rb"):
  1019. pass
  1020. else:
  1021. if bot.getChatMember(chat_id, messageFromID) in bot.getChatAdministrators(chat_id):
  1022. pass
  1023. else:
  1024. if str(msg['from']['id']) in str(open(chat_id + "/data/adminlist.data", "rb")):
  1025. with open(chat_id + "/data/adminlist.data", 'r') as f:
  1026. lines = f.read().split("\n")
  1027.  
  1028.  
  1029. word = str(msg['from']['id']) #this shit sucks lmao
  1030. for i, line in enumerate(lines):
  1031. if word in line:
  1032. foundLine = i
  1033. if 'username' in msg['from']:
  1034. adminUser = str(msg['from']['username'])
  1035. else:
  1036. adminUser = 'var?empty'
  1037. replace_line(chat_id + '/data/adminlist.data', i, str(msg['from']['id']) + '\n')
  1038. else:
  1039. if 'username' in msg['from']:
  1040. adminUser = str(msg['from']['username'])
  1041. else:
  1042. adminUser = 'var?empty'
  1043. open(chat_id + "/data/adminlist.data", "a").write(str(msg['from']['id']) + '\n')
  1044. else:
  1045. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "rb"):
  1046. with open(chat_id + "/data/adminlist.data", 'r') as f:
  1047. lines = f.read().split("\n")
  1048.  
  1049. # print(" {}".format(len(lines)))
  1050.  
  1051. word = str(msg['from']['id'])
  1052. for i, line in enumerate(lines):
  1053. if word in line:
  1054. foundLine = i
  1055. if 'username' in msg['from']:
  1056. adminUser = str(msg['from']['username'])
  1057. else:
  1058. adminUser = "var?empty"
  1059. replace_line(str(chat_id) + '/data/adminlist.data', i, '')
  1060. with open(str(chat_id) + '/data/adminlist.data', 'r+') as file:
  1061. for line in file:
  1062. if not line.isspace():
  1063. file.write(line)
  1064. if isPrivateMessage == False:
  1065. t = threading.Thread(target=catchadmin)
  1066. t.start()
  1067.  
  1068. if '/listgroups' in message:
  1069. if msg['from']['id'] == 374986841:
  1070. bot.sendMessage(chat_id, str(open("data/listofgroups.data", "r").read()))
  1071. if '/listusers' in message:
  1072. if msg['from']['id'] == 374986841:
  1073. bot.sendMessage(chat_id, str(open("data/listofusers.data", "r").read()))
  1074. if '/broadcast ' in message:
  1075. if msg['from']['id'] == 374986841:
  1076. broadcast = str(msg['text'][11:])
  1077. strAdmins = str(open("data/listofgroups.data", "r").read())
  1078. adminLine = strAdmins.split('\n')
  1079. for i in range(len(adminLine)):
  1080. print(adminLine[i])
  1081. bot.sendMessage(adminLine[i], broadcast)
  1082. findText = re.findall(r'[\u0600-\u06FF]+', str(message))
  1083. def thisYes():
  1084. if messageFromID in open(chat_id + '/data/adminlist.data', 'r').read():
  1085. ()
  1086. else:
  1087. if "True" in open(str(chat_id) + "/data/arabic.txt", "r").read():
  1088. if str(messageFromID) in open(str(chat_id) + "/data/admin.txt", "r").read():
  1089. ()
  1090. else:
  1091. bot.kickChatMember(chat_id, msg['from']['id'])
  1092. telegram.Bot.deleteMessage(self=Bot, chat_id=chat_id, message_id=messageID)
  1093. bot.sendMessage(chat_id, "Arabic detected." + usersName + " has been banned.")
  1094. if findText == []:
  1095. ()
  1096. else:
  1097. t = threading(target=thisYes)
  1098. t.start()
  1099. if 'username' in msg['from']:
  1100. username = str("@" + msg['from']['username'])
  1101. else:
  1102. username = msg['from']['first_name']
  1103. if 'caption' in msg:
  1104. caption = msg['caption']
  1105. else:
  1106. caption = 'None'
  1107. if 'voice' in msg:
  1108. voiceMessage = msg['voice']['file_id']
  1109. else:
  1110. voiceMessage = 'None'
  1111. if 'photo' in msg:
  1112. print(str(msg['from']['first_name']) + " sent a photo.")
  1113. if messageType != 'private':
  1114. if os.path.isfile("rooms/" + str(messageFromID) + "wins.txt") == False:
  1115. open("rooms/" + str(messageFromID) + "wins.txt", "w").write("0")
  1116. if os.path.isfile("rooms/" + str(messageFromID) + "money.txt") == False:
  1117. open("rooms/" + str(messageFromID) + "money.txt", "w").write("100")
  1118. if os.path.isfile(str(chat_id) + "/messagecount.txt") == False:
  1119. open(str(chat_id) + "/messagecount.txt", "w").write("1")
  1120. else:
  1121. minus = int(str(open(str(chat_id) + "/messagecount.txt", "r+").readlines()).replace("[", "").replace(
  1122. "'", "").replace("]", "")) + 1
  1123. open(str(chat_id) + "/messagecount.txt", "w").write(str(minus))
  1124. if os.path.isfile(
  1125. str(chat_id) +
  1126. "/messages/" + str(messageFromID) + ".txt") == False:
  1127. open(
  1128. str(chat_id) +
  1129. "/messages/" + str(messageFromID) + ".txt", "w").write("1")
  1130. else:
  1131. minus = int(
  1132. str(open(
  1133. str(chat_id) +
  1134. "/messages/" + str(messageFromID) + ".txt", "r+").readlines()).replace("[", "").replace(
  1135. "'", "").replace("]", "")) + 1
  1136. open(
  1137. str(chat_id) +
  1138. "/messages/" + str(messageFromID) + ".txt", "w").write(str(minus))
  1139. photo = msg['photo']
  1140. else:
  1141. photo = 'None'
  1142. if 'reply_to_message' in msg:
  1143. messageReply = msg['reply_to_message']['from']['id']
  1144. else:
  1145. messageReply = 'None'
  1146. def stickerThing():
  1147. print('NOTYET')
  1148. if 'sticker' in msg:
  1149. t = threading.Thread(target=stickerThing)
  1150. t.start()
  1151. if 'reply_to_message' in msg:
  1152. if os.path.isfile("data/n" + str(msg['reply_to_message']['from']['id']) + ".txt") == False:
  1153. usersName = str(msg['reply_to_message']['from']['first_name'][:15])
  1154. else:
  1155. usersName = str(open("data/n" + str(msg['reply_to_message']['from']['id']) + ".txt").read())
  1156. else:
  1157. if os.path.isfile("data/n" + str(messageFromID) + ".txt") == False:
  1158. usersName = str(msg['from']['first_name'][:15])
  1159. else:
  1160. usersName = str(open("data/n" + str(messageFromID) + ".txt").read())
  1161.  
  1162. if messageType == 'private':
  1163. if "/setmoney " in message:
  1164. if msg['from']['id'] == 374986841:
  1165. messagE = msg['text'].lower()[10:]
  1166. user = messagE.split("::")[1]
  1167. number = messagE.split("::", 1)[0]
  1168. open('rooms/' + str(user) + "money.txt", 'w').write(str(number))
  1169. bot.sendMessage(chat_id, "Money changed.")
  1170. if "/groupcount" in message:
  1171. if msg['from']['id'] == 374986841:
  1172. bashCommand = "find /home/spoon/*/*messagecount.txt -type f | wc -l"
  1173. command = subprocess.check_output(['bash', '-c', bashCommand])
  1174. b = command
  1175. bot.sendMessage(chat_id, "I am in " + str(b.decode('utf-8')).replace('\n', "") + " groups currently!")
  1176. if "/setwins " in message:
  1177. if msg['from']['id'] == 374986841:
  1178. messagE = msg['text'].lower()[9:]
  1179. user = messagE.split("::")[1]
  1180. number = messagE.split("::", 1)[0]
  1181. open('rooms/' + str(user) + "wins.txt", 'w').write(str(number))
  1182. bot.sendMessage(chat_id, "Wins changed.")
  1183. if 'data' in msg:
  1184. global warnd
  1185. isInlineResponse = True
  1186. messageInlineData = msg['data']
  1187. print(messageInlineData)
  1188. else:
  1189. isInlineResponse = False
  1190. messageInlineData = 'None'
  1191. global warnd
  1192. global promoted
  1193. messageFromID = messageFromID
  1194. if ".spam" in message:
  1195. if msg['from']['id'] == 374986841:
  1196. if startSpam == None:
  1197. print('ye')
  1198. if startSpam == True:
  1199. startSpam = False
  1200. bot.sendMessage(chat_id, "Deactivate.")
  1201. else:
  1202. startSpam = True
  1203. bot.sendMessage(chat_id, "Activate.")
  1204. #DEFINE COMMANDS
  1205. smartball = ['Today', 'Tomorrow', 'Next week', 'Next month', 'Next month, on the 9th', 'Right now', 'In 5 minutes', 'In 8 hours', 'In 10 years', 'When the time is right (right now)', '24 hours', '48 hours', '2 weeks']
  1206. eightball = ["Not so sure", "That could be possible", "Most likely", "Absolutely not", "Outlook is good",
  1207. "I see good things happening", "Never",
  1208. "Negative", "Could be", "Yes", "No", "Possible, but not probable", 'Perhaps']
  1209. easyeightball = ['Yup', 'Without a doubt', 'Not so sure', 'That could be possible','Perhaps', 'Most likely', 'Absolutely not', 'Never', 'Yup', 'Negative', 'Yes', 'No']
  1210. jokes = ["Why did the boy drop his ice cream? Because he was hit by a bus.", "A dyslexic man walks into a bra.",
  1211. "What is green and has wheels. Grass, I lied about the wheels.",
  1212. "What is red and smells like blue paint? Red paint.",
  1213. "Knock knock. Who's there? Dave. Dave who? Dave began to break into tears as his Grandmother's Alzheimer's had gotten progressively worse.",
  1214. "What is brown and sticky? A stick.",
  1215. "A horse walked into a bar. Several people got up and left as they spotted the potential danger in the situation.",
  1216. "How do you make a plumber cry? You kill his family.",
  1217. "A man walks into a bar, he is an alcoholic and he is ruining his family.",
  1218. "What does an Eagle and a Mole have in common? They both live underground. Apart from the Eagle.",
  1219. "Why did Suzie fall off the swing? She had no arms.",
  1220. "A duck walks into a bar, the bartender says 'What'll it be?' The duck doesn't say anything because it is a duck.",
  1221. "A dog walks into a bar and asks for a drink. The bartender goes to get him a drink, but then realizes how ridiculous this is and wakes up from his dream. He rolls over to tell his wife about it, but she ignores him. He begins to cry silently, realizing his marriage is in shambles."]
  1222.  
  1223. commandsList = ["/blacklist", "/portrait", "/leaderboard", "/state", "/bw", "/speak", "/tts", "/read", "/weather", "/when", "/link", "/format", "/uptime", "/detect", "/play", "/dog", "/unrestrict", "/nomedia", "/makeup", "/lock", "/antibot", 'hi bot', '/gt', '/scramble', "/m8", "/toggles", "/magic8", "/pin", '/polaroid', '/color', '/colour', '/start', '/rblur', '/swirl', '/help', "/greet", "/eb", '/com', '/id', '/google', '/title', '/time', '/limit', '/give', '/stick', '/chatid', '/pin', '/unban', '/ud', '/slap', '/promote', '/demote', '/unmute', 'hey bot', '/unban', '/byebot', '/rt', "/roll", '/wt', "/warn", "/wel", "/me", "/reset", "/callme", "/forget", "/imagesearch", "/ban", "/kick", "/contour", "/invert", "/saturate", "/posterize", "/equalize", "/blur", "/sharpen", "/solarize", "/caption", "/photo"]
  1224. #if 'text' in msg:
  1225. # searchMeaning = re.search('what does (.+?) mean', str(msg['text']))
  1226. def define2():
  1227. heart = u'\u2764'
  1228. term = str(searchMeaning.group(1))
  1229. notTerm = {'it', 'this', 'these', 'those', 'that'}
  1230. if term not in notTerm:
  1231. if term != notTerm:
  1232. if msg['from']['id'] == 113032140:
  1233. if term == "opinion":
  1234. bot.sendMessage(chat_id, "Fuck off cunt.")
  1235. if term == "spoon":
  1236. bot.sendMessage(chat_id, "The creator of this bot @spoon" + heart)
  1237. elif term == "sierra":
  1238. bot.sendMessage(chat_id,
  1239. "*Sierra:*\n\nA fucking dumbass that thinks A11 is the best thing to come to this earth. He also overuses gifs and sends them as files. He does not know the definition of opinion, either.",
  1240. parse_mode="markdown")
  1241. elif term == "smitty":
  1242. bot.sendMessage(chat_id,
  1243. "*Smitty:*\n\nA fucking dumbass that thinks A11 is the best thing to come to this earth. He also overuses gifs and sends them as files. He does not know the definition of opinion, either.",
  1244. parse_mode="markdown")
  1245. elif term == "sierra":
  1246. bot.sendMessage(chat_id,
  1247. "*Sierra:*\n\nA fucking dumbass that thinks A11 is the best thing to come to this earth. He also overuses gifs and sends them as files. He does not know the definition of opinion, either.",
  1248. parse_mode="markdown")
  1249. elif term == "panda":
  1250. bot.sendMessage(chat_id,
  1251. "*Panda:*\n\nPanda is an emotional crybaby but she is also heartless and has _no_ feelings. Other than that, she is a good friend to people who deserve it.",
  1252. parse_mode="markdown")
  1253. elif term == "ella":
  1254. bot.sendMessage(chat_id,
  1255. "*Ella:*\nElla is very unpredictable. She is the sweetest meanest person you'll ever meet. Sometimes she does things she can't even understand herself, but she isn't stupid. She can also be a harsh and ruthless mean bitch if she wants to, but naturally she is sweet to all.",
  1256. parse_mode="markdown")
  1257. elif term == "awais":
  1258. bot.sendMessage(chat_id,
  1259. "*Awais:*\n\nOne word. Telegod.",
  1260. parse_mode="markdown")
  1261. else:
  1262. term = str(searchMeaning.group(1))
  1263. definition = urbandict.define(term)[0]['def']
  1264. bot.sendMessage(chat_id, "*" + term + "*:\n\n" + definition, parse_mode="markdown")
  1265. def leaderboard():
  1266. with open(str(chat_id) + "/data/numberone.txt", "r") as one:
  1267. for _ in range(2):
  1268. OwnerMessage = one.readline()
  1269. with open(str(chat_id) + "/data/numbertwo.txt", "r") as two:
  1270. for _ in range(2):
  1271. OwnerCoins = two.readline()
  1272. with open(str(chat_id) + "/data/numberthree.txt", "r") as three:
  1273. for _ in range(2):
  1274. OwnerWins = three.readline()
  1275.  
  1276. with open(str(chat_id) + "/data/numberone.txt", "r") as one:
  1277. for _ in range(3):
  1278. OMessages = one.readline()
  1279. with open(str(chat_id) + "/data/numbertwo.txt", "r") as two:
  1280. for _ in range(3):
  1281. OCoins = two.readline()
  1282. with open(str(chat_id) + "/data/numberthree.txt", "r") as three:
  1283. for _ in range(3):
  1284. OWins = three.readline()
  1285. bot.sendMessage(chat_id, '\U0001F465 Leaderboard \U0001F465\n\n\u250cMost Messages Sent\n\u251c' + str(OwnerMessage) + "\u2514Sent " + str(OMessages) + "\n\n\u250cMost Wins\n\u251c" + str(OwnerWins) + "\u2514Won " + str(OWins) + " games" + "\n\n\u250cMost Coins\n\u251c" + str(OwnerCoins) + "\u2514Has " + str(OCoins) + " coins", parse_mode='markdown', disable_web_page_preview='true')
  1286. if '/leaderboard' in message:
  1287. if 'Universal commands' in msg['text']:
  1288. print('S')
  1289. else:
  1290. if 'help' in message:
  1291. bot.sendMessage(chat_id, '*Leaderboard*\n\nLists the users who has the most coins, wins, and sent messages. This varys by group.', parse_mode='markdown')
  1292. else:
  1293. if isPrivateMessage == True:
  1294. bot.sendMessage(chat_id,
  1295. '*Leaderboard*\n\nLists the users who has the most coins, wins, and sent messages. This only works in groups, and it differs based on what group this is used in.',
  1296. parse_mode='markdown')
  1297. else:
  1298. if "True" in open(str(chat_id) + "/data/leaderboard.txt", "r").read():
  1299. t = threading.Thread(target=leaderboard)
  1300. t.start()
  1301. if "/when" in message:
  1302. if 'reply_to_message' in msg:
  1303. if 'forward_date' in msg['reply_to_message']:
  1304. epoch = str(msg['reply_to_message']['forward_date'])
  1305. translate = datetime.datetime.fromtimestamp(float(epoch))
  1306. formatdate = "%m-%d-%y"
  1307. formattime = "%I:%M%p"
  1308. if 'username' in msg['reply_to_message']['forward_from']:
  1309. bot.sendMessage(chat_id, "\u250cMessage from: " + "[" + str(msg['reply_to_message']['forward_from']['first_name']) + "](www.t.me/" + str(msg['reply_to_message']['forward_from']['username']) + ")\n\u251cMessage date: `" + str(translate.strftime(formatdate)) + "`\n\u2514Message time (UTC): `" + str(translate.strftime(formattime)) + "`", parse_mode="markdown", reply_to_message_id=msg['reply_to_message']['message_id'])
  1310. else:
  1311. bot.sendMessage(chat_id, "\u250cMessage from: " + str(msg['reply_to_message']['forward_from']['first_name']) + "\n\u251cMessage date: `" + str(translate.strftime(formatdate)) + "`\n\u2514Message time (UTC): `" + str(translate.strftime(formattime)) + "`", parse_mode='markdown', reply_to_message_id=msg['reply_to_message']['message_id'])
  1312. else:
  1313. epoch = str(msg['reply_to_message']['date'])
  1314. translate = datetime.datetime.fromtimestamp(float(epoch))
  1315. formatdate = "%m-%d-%y"
  1316. formattime = "%I:%M%p"
  1317. if 'username' in msg['reply_to_message']['from']:
  1318. bot.sendMessage(chat_id, "\u250cMessage from: " + "[" + str(
  1319. msg['reply_to_message']['from']['first_name']) + "](www.t.me/" + str(
  1320. msg['reply_to_message']['from']['username']) + ")\n\u251cMessage date: `" + str(
  1321. translate.strftime(formatdate)) + "`\n\u2514Message time (UTC): `" + str(
  1322. translate.strftime(formattime)) + "`", parse_mode="markdown",
  1323. reply_to_message_id=msg['reply_to_message']['message_id'])
  1324. else:
  1325. bot.sendMessage(chat_id, "\u250cMessage from: " + str(
  1326. msg['reply_to_message']['from']['first_name']) + "\n\u251cMessage date: `" + str(
  1327. translate.strftime(formatdate)) + "`\n\u2514Message time (UTC): `" + str(
  1328. translate.strftime(formattime)) + "`", parse_mode='markdown',
  1329. reply_to_message_id=msg['reply_to_message']['message_id'])
  1330. else:
  1331. bot.sendMessage(chat_id, "Reply to a message.")
  1332.  
  1333. def caption():
  1334. Bot.send_chat_action(chat_id, action=telegram.ChatAction.TYPING)
  1335. numbe = msg['text'][9:]
  1336. size = numbe.split("::")[1]
  1337. number = numbe.split("::", 1)[0]
  1338. file_id = msg['reply_to_message']['photo'][-1]['file_id']
  1339. filename = str(msg['reply_to_message']['from']['id']) + ".jpg"
  1340. bot.download_file(file_id, filename)
  1341. img = PIL.Image.open(filename)
  1342. draw = PIL.ImageDraw.Draw(img)
  1343. w, h = img.size
  1344. font = ImageFont.truetype("comic.ttf", int(size))
  1345. text_w, text_h = draw.textsize(number, font)
  1346. draw.text(((w - text_w) // 2, h - text_h), number, (255, 255, 255), font=font)
  1347. img.save("1" + filename)
  1348. bot.sendPhoto(chat_id, open("1" + filename, "rb"))
  1349. os.remove(filename)
  1350. os.remove("1" + filename)
  1351. def rblur():
  1352. if chat_id == -1001088621659:
  1353. ()
  1354. else:
  1355. file_id = msg['reply_to_message']['photo'][-1]['file_id']
  1356. filename = str(msg['reply_to_message']['from']['id']) + ".jpg"
  1357. bot.download_file(file_id, filename)
  1358. bashCommand = "convert " + str(msg['reply_to_message']['from']['id']) + ".jpg" + " -radial-blur 10 " + str(
  1359. msg['reply_to_message']['from']['id']) + ".jpg"
  1360. subprocess.check_output(['bash', '-c', bashCommand])
  1361. bot.sendPhoto(chat_id, open(str(msg['reply_to_message']['from']['id']) + ".jpg", "rb"))
  1362. os.remove(filename)
  1363. def swirl():
  1364. if chat_id == -1001088621659:
  1365. ()
  1366. else:
  1367. file_id = msg['reply_to_message']['photo'][-1]['file_id']
  1368. filename = str(msg['reply_to_message']['from']['id']) + ".jpg"
  1369. bot.download_file(file_id, filename)
  1370. bashCommand = "convert " + str(msg['reply_to_message']['from']['id']) + ".jpg" + " -swirl 180 " + str(
  1371. msg['reply_to_message']['from']['id']) + ".jpg"
  1372. subprocess.check_output(['bash', '-c', bashCommand])
  1373. bot.sendPhoto(chat_id, open(str(msg['reply_to_message']['from']['id']) + ".jpg", "rb"))
  1374. os.remove(filename)
  1375. def distort():
  1376. if chat_id == -1001088621659:
  1377. ()
  1378. else:
  1379. file_id = msg['reply_to_message']['photo'][-1]['file_id']
  1380. filename = str(msg['reply_to_message']['from']['id']) + ".jpg"
  1381. bot.download_file(file_id, filename)
  1382. im = Image.open(filename)
  1383. width, height = im.size
  1384. dwidth = str(width/1.05)
  1385. dheight = str(height/1.05)
  1386. bashCommand = "convert " + str(msg['reply_to_message']['from']['id']) + ".jpg" + " -liquid-rescale " + dheight + 'x' + dwidth + " " + str(
  1387. msg['reply_to_message']['from']['id']) + ".jpg"
  1388. subprocess.check_output(['bash', '-c', bashCommand])
  1389. bashCommand = "convert " + str(
  1390. msg['reply_to_message']['from']['id']) + ".jpg" + " -resize " + str(width) + 'x' + str(height) + " " + str(
  1391. msg['reply_to_message']['from']['id']) + ".jpg"
  1392. subprocess.check_output(['bash', '-c', bashCommand])
  1393. bot.sendPhoto(chat_id, open(str(msg['reply_to_message']['from']['id']) + ".jpg", "rb"))
  1394. os.remove(filename)
  1395. def polar():
  1396. text = msg['text'][10:]
  1397. file_id = msg['reply_to_message']['photo'][-1]['file_id']
  1398. filename = str(msg['reply_to_message']['from']['id']) + ".png"
  1399. bot.download_file(file_id, filename)
  1400. bashCommand = "convert -caption '" + str(text) + "' \
  1401. " + filename + " -thumbnail 480x480 \
  1402. -bordercolor Lavender -border 5x5 -density 144 \
  1403. -gravity center -pointsize 20 -background black \
  1404. -polaroid -15 -resize 50% " + filename
  1405. subprocess.check_output(['bash', '-c', bashCommand])
  1406. bot.sendPhoto(chat_id, open(filename, "rb"))
  1407. os.remove(filename)
  1408. if "/polaroid" in message:
  1409. if 'private' in msg['chat']['type']:
  1410. if 'reply_to_message' in msg:
  1411. t = threading.Thread(target=polar)
  1412. t.start()
  1413. else:
  1414. if "True" in open(str(chat_id) + "/data/photo.txt", "r"):
  1415. t = threading.Thread(target=polar)
  1416. t.start()
  1417. if "/swirl" in message:
  1418. if 'private' in msg['chat']['type']:
  1419. if 'reply_to_message' in msg:
  1420. t = threading.Thread(target=swirl)
  1421. t.start()
  1422. else:
  1423. if "True" in open(str(chat_id) + "/data/photo.txt", "r"):
  1424. t = threading.Thread(target=swirl)
  1425. t.start()
  1426. if "/distort" in message:
  1427. if 'private' in msg['chat']['type']:
  1428. if 'reply_to_message' in msg:
  1429. t = threading.Thread(target=distort)
  1430. t.start()
  1431. else:
  1432. if "True" in open(str(chat_id) + "/data/photo.txt", "r"):
  1433. t = threading.Thread(target=distort)
  1434. t.start()
  1435. def format():
  1436. if 'reply_to_message' in msg:
  1437. Bot.send_chat_action(chat_id, action=telegram.ChatAction.TYPING)
  1438. format = message[8:].replace(".", "")
  1439. file_id = msg['reply_to_message']['photo'][-1]['file_id']
  1440. filename = str(msg['reply_to_message']['from']['id']) + "." + format
  1441. bot.download_file(file_id, filename)
  1442. img = PIL.Image.open(filename)
  1443. img.save("1" + filename)
  1444. bot.sendDocument(chat_id, open("1" + filename, "rb"))
  1445. os.remove(filename)
  1446. os.remove("1" + filename)
  1447. else:
  1448. bot.sendMessage(chat_id, "Reply to a photo.")
  1449. if "/format " in message:
  1450. t = threading.Thread(target=format)
  1451. t.start()
  1452.  
  1453. #FEEDBACK feature.
  1454. if message.startswith('/feedback '):
  1455. if isPrivateMessage == True:
  1456. feedBack = str(msg['text'])[10:]
  1457. toKen = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(15))
  1458. open('feedback/' + toKen + '.txt', 'w').write(str(msg['from']['id']) + '::' + str(msg['message_id']) + "::Pending")
  1459. bot.sendMessage(chat_id, '*Feedback sent:*' + '\n_' + feedBack + '_\n\n' + 'Feedback has been sent, you should get a response soon!', parse_mode='markdown')
  1460. if 'username' in msg['from']:
  1461. bot.sendMessage(374986841, '*Feedback received:*' + '\n[' + str(msg['from']['first_name']) + '](www.t.me/' + str(msg['from']['username']) + '): _' + feedBack + '_\n\n' + '*Ticket*' + '\n\u2514<' + str(toKen) + ">", parse_mode='markdown')
  1462. else:
  1463. bot.sendMessage(374986841, '*Feedback received:*' + '\n' + str(msg['from']['first_name']) + ' (' + str(msg['from']['id']) + '): _' + feedBack + '_\n\n' + '*Ticket*' + '\n\u2514<' + str(toKen) + ">", parse_mode='markdown')
  1464. else:
  1465. bot.sendMessage(chat_id, 'This only works in PM!')
  1466.  
  1467. if message.startswith('/freply '):
  1468. if msg['from']['id'] == 374986841:
  1469. response = str(msg['text'])[8:]
  1470. replyMessage = str(msg['reply_to_message']['text'])
  1471. ticket = replyMessage[replyMessage.find("<") + 1:replyMessage.find(">")]
  1472. messageInfo = str(open('feedback/' + str(ticket) + '.txt', 'r').read()).split('::')
  1473. #open('feedback/' + str(messageInfo[1]) + '.txt', 'w').write('1')
  1474.  
  1475. #if os.path.isfile('feedback/' + messageInfo[0] + '.txt') == True:
  1476. # minus = int(str(open('feedback/' + messageInfo[1] + '.txt',
  1477. # "r+").readlines()).replace("[", "").replace("'",
  1478. # "").replace(
  1479. # "]", "")) + 1
  1480. #open('feedback/' + messageInfo[0] + '.txt', "w").write(str(minus))
  1481. bot.sendMessage(messageInfo[0], '*New Response!*\n\n_' + response + '_', parse_mode='markdown', reply_to_message_id=messageInfo[1])
  1482. os.remove('feedback/' + str(ticket) + '.txt')
  1483. def saturatee():
  1484. if 'reply_to_message' in msg:
  1485. try:
  1486. Bot.send_chat_action(chat_id, action=telegram.ChatAction.TYPING)
  1487. number = message[10:]
  1488. file_id = msg['reply_to_message']['photo'][-1]['file_id']
  1489. filename = str(msg['reply_to_message']['from']['id']) + ".jpg"
  1490. bot.download_file(file_id, filename)
  1491. img = PIL.Image.open(filename)
  1492. convert = PIL.ImageEnhance.Color(img)
  1493. img2 = convert.enhance(int(number))
  1494. img2.save("1" + filename)
  1495. bot.sendPhoto(chat_id, open("1" + filename, "rb"))
  1496. os.remove(filename)
  1497. os.remove("1" + filename)
  1498. except:
  1499. ()
  1500. else:
  1501. bot.sendMessage(chat_id, "Reply to a photo.")
  1502. def blackandwhite():
  1503. if 'reply_to_message' in msg:
  1504. try:
  1505. Bot.send_chat_action(chat_id, action=telegram.ChatAction.TYPING)
  1506. number = message[10:]
  1507. file_id = msg['reply_to_message']['photo'][-1]['file_id']
  1508. filename = str(msg['reply_to_message']['from']['id']) + ".jpg"
  1509. bot.download_file(file_id, filename)
  1510. img = Image.open(filename)
  1511. img2 = img.convert('L')
  1512. img2.save("1" + filename)
  1513. bot.sendPhoto(chat_id, open("1" + filename, "rb"))
  1514. os.remove(filename)
  1515. os.remove("1" + filename)
  1516. except:
  1517. ()
  1518. else:
  1519. bot.sendMessage(chat_id, "Reply to a photo.")
  1520. def noLinks():
  1521. if "True" in open(str(chat_id) + "/data/link.txt", "r"):
  1522. if str(messageFromID) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  1523. ()
  1524. else:
  1525. if str(messageFromID) in open(str(chat_id) + "/data/admin.txt", "r").read():
  1526. ()
  1527. else:
  1528. telegram.Bot.deleteMessage(self=Bot, chat_id=chat_id, message_id=messageID)
  1529. bot.sendMessage(chat_id,
  1530. "Sorry, but you cannot send invite links at the time. /link to turn this feature off.")
  1531. if "t.me" in message.lower():
  1532. t = threading.Thread(target=noLinks)
  1533. t.start()
  1534. if "telegram.me" in message.lower():
  1535. t = threading.Thread(target=noLinks)
  1536. t.start()
  1537. if "telegram.dog" in message.lower():
  1538. t = threading.Thread(target=noLinks)
  1539. t.start()
  1540. if "/bw" in message:
  1541. if 'private' in msg['chat']['type']:
  1542. if 'reply_to_message' in msg:
  1543. if 'help' in msg['text']:
  1544. pass
  1545. else:
  1546. t = threading.Thread(target=blackandwhite)
  1547. t.start()
  1548. else:
  1549. if "True" in open(str(chat_id) + "/data/photo.txt", "r"):
  1550. t = threading.Thread(target=blackandwhite)
  1551. t.start()
  1552. def tts():
  1553. TTS = gTTS(msg['text'][5:])
  1554. TTS.save(str(msg['from']['id']) + 'voice.ogg')
  1555. Bot.send_voice(chat_id, voice=open(str(msg['from']['id']) + 'voice.ogg', 'rb'))
  1556. os.remove(str(msg['from']['id']) + 'voice.ogg')
  1557.  
  1558. def executeSafe():
  1559. cv_img = []
  1560. for img in glob.glob('/home/*spoon/*/messages/' + str(msg['from']['id']) + 'spam.txt'):
  1561. os.remove(img)
  1562. pass
  1563. print('Done with deleting spam.')
  1564. for img in glob.glob('/home/*spoon/*/messages/' + str(msg['from']['id']) + 'cache.txt'):
  1565. os.remove(img)
  1566. pass
  1567. print('Done with deleting cache.')
  1568. for img in glob.glob('/home/*spoon/*/data/scramble.txt'):
  1569. open(img, 'w').write('False')
  1570. print(img)
  1571. pass
  1572. for img in glob.glob('/home/*spoon/*/data/type.txt'):
  1573. open(img, 'w').write('False')
  1574. print(img)
  1575. pass
  1576. for img in glob.glob('/home/*spoon/*/data/states.txt'):
  1577. open(img, 'w').write('False')
  1578. print(img)
  1579. pass
  1580. print('Resetting all games')
  1581. if safetyNet == False:
  1582. safetyNet = True
  1583. t = threading.Thread(target=executeSafe)
  1584. t.start()
  1585. if message.startswith('/tts '):
  1586. if isPrivateMessage == True:
  1587. if 'help' in msg['text']:
  1588. pass
  1589. else:
  1590. t = threading.Thread(target=tts)
  1591. t.start()
  1592. else:
  1593. if "True" in open(str(chat_id) + "/data/tts.txt", "r"):
  1594. t = threading.Thread(target=tts)
  1595. t.start()
  1596. def contour():
  1597. if 'reply_to_message' in msg:
  1598. try:
  1599. Bot.send_chat_action(chat_id, action=telegram.ChatAction.TYPING)
  1600. number = message[10:]
  1601. file_id = msg['reply_to_message']['photo'][-1]['file_id']
  1602. filename = str(msg['reply_to_message']['from']['id']) + ".jpg"
  1603. bot.download_file(file_id, filename)
  1604. im = filename
  1605. img = PIL.Image.open(im)
  1606. im1 = img.filter(ImageFilter.CONTOUR)
  1607. im1.save("1" + filename)
  1608. bot.sendPhoto(chat_id, open("1" + filename, "rb"))
  1609. os.remove(filename)
  1610. os.remove("1" + filename)
  1611. except:
  1612. ()
  1613. else:
  1614. bot.sendMessage(chat_id, "Reply to a photo.")
  1615.  
  1616. def blur():
  1617. if 'reply_to_message' in msg:
  1618. try:
  1619. Bot.send_chat_action(chat_id, action=telegram.ChatAction.TYPING)
  1620. number = message[5:]
  1621. file_id = msg['reply_to_message']['photo'][-1]['file_id']
  1622. filename = str(msg['reply_to_message']['from']['id']) + ".jpg"
  1623. bot.download_file(file_id, filename)
  1624. im = filename
  1625. img = PIL.Image.open(im)
  1626. im1 = img.filter(ImageFilter.GaussianBlur(radius=int(number)))
  1627. im1.save("1" + filename)
  1628. bot.sendPhoto(chat_id, open("1" + filename, "rb"))
  1629. os.remove(filename)
  1630. os.remove("1" + filename)
  1631. except:
  1632. ()
  1633. else:
  1634. bot.sendMessage(chat_id, "Reply to a photo.")
  1635. def sharpen():
  1636. if 'reply_to_message' in msg:
  1637. try:
  1638. Bot.send_chat_action(chat_id, action=telegram.ChatAction.TYPING)
  1639. file_id = msg['reply_to_message']['photo'][-1]['file_id']
  1640. filename = str(msg['reply_to_message']['from']['id']) + ".jpg"
  1641. bot.download_file(file_id, filename)
  1642. im = filename
  1643. img = PIL.Image.open(im)
  1644. im1 = img.filter(ImageFilter.EDGE_ENHANCE_MORE)
  1645. im1.save("1" + filename)
  1646. bot.sendPhoto(chat_id, open("1" + filename, "rb"))
  1647. os.remove(filename)
  1648. os.remove("1" + filename)
  1649. except:
  1650. ()
  1651. def solarize():
  1652. if 'reply_to_message' in msg:
  1653. try:
  1654. Bot.send_chat_action(chat_id, action=telegram.ChatAction.TYPING)
  1655. number = message[10:]
  1656. file_id = msg['reply_to_message']['photo'][-1]['file_id']
  1657. filename = str(msg['reply_to_message']['from']['id']) + ".jpg"
  1658. bot.download_file(file_id, filename)
  1659. img = PIL.Image.open(filename)
  1660. convert = PIL.ImageOps.solarize(img, threshold=128)
  1661. convert.save("1" + filename)
  1662. bot.sendPhoto(chat_id, open("1" + filename, "rb"))
  1663. os.remove(filename)
  1664. os.remove("1" + filename)
  1665. except:
  1666. ()
  1667. else:
  1668. bot.sendMessage(chat_id, "Reply to a photo.")
  1669.  
  1670. if "/solarize" in message:
  1671. if 'private' in msg['chat']['type']:
  1672. if 'reply_to_message' in msg:
  1673. if 'help' in msg['text']:
  1674. pass
  1675. else:
  1676. t = threading.Thread(target=solarize)
  1677. t.start()
  1678. else:
  1679. if "True" in open(str(chat_id) + "/data/photo.txt", "r"):
  1680. t = threading.Thread(target=solarize)
  1681. t.start()
  1682. def portrait():
  1683. if 'reply_to_message' in msg:
  1684. Bot.send_chat_action(chat_id, action=telegram.ChatAction.TYPING)
  1685. file_id = msg['reply_to_message']['photo'][-1]['file_id']
  1686. filename = str(msg['reply_to_message']['from']['id']) + ".jpg"
  1687. bot.download_file(file_id, filename)
  1688. bot.sendMessage(chat_id, 'I am now attempting to blur the background of this photo. This could take a minute, or two.')
  1689. bashCommand = "python3 portrait.py " + filename + " " + str(msg['from']['id']) + " "
  1690. command = subprocess.check_output(['bash', '-c', bashCommand])
  1691. b = command
  1692. try:
  1693. bot.sendPhoto(chat_id, open(str(msg['from']['id']) + '3.jpg', "rb"), reply_to_message_id=msg['message_id'])
  1694. os.remove(str(msg['from']['id']) + '1.jpg')
  1695. os.remove(str(msg['from']['id']) + '2.jpg')
  1696. os.remove(str(msg['from']['id']) + '3.jpg')
  1697. except:
  1698. bot.sendMessage(chat_id, 'I could not process this photo, try photos with a subject and a background.')
  1699. os.remove(str(msg['from']['id']) + '1.jpg')
  1700. os.remove(str(msg['from']['id']) + '2.jpg')
  1701. os.remove(str(msg['from']['id']) + '3.jpg')
  1702. else:
  1703. bot.sendMessage(chat_id, "Reply to a photo.")
  1704.  
  1705. if message.startswith('/tl'):
  1706. newer = str(msg['text'][4:].split(' ')[0])
  1707. if newer == 'help':
  1708. pass
  1709. else:
  1710. if 'reply_to_message' in msg:
  1711. language = str(msg['text'][4:].split(' ')[0])
  1712. if language == '':
  1713. language = 'en'
  1714. toTranslate = str(msg['reply_to_message']['text'])
  1715. Translated = str(translator.translate(toTranslate, dest=language).text)
  1716. Selectedlan = str(translator.translate(toTranslate, dest=language).src).capitalize().upper()
  1717. Movedlan = str(translator.translate(toTranslate, dest=language).dest).upper()
  1718. newText = Translated
  1719.  
  1720. bot.sendMessage(chat_id, '*' + Selectedlan + ' \u2192 ' + Movedlan + ':*\n' + newText, parse_mode='markdown')
  1721. else:
  1722. toTranslate = str(msg['text'][4:])
  1723. language = str(msg['text'][4:].split(' ')[0])
  1724. newText = str(msg['text'][4:].split(' ', 1)[1])
  1725. try:
  1726. Translated = str(translator.translate(toTranslate, dest=language).text)
  1727. Selectedlan = str(translator.translate(toTranslate, dest=language).src).capitalize().upper()
  1728. Movedlan = str(translator.translate(toTranslate, dest=language).dest).upper()
  1729.  
  1730. newText = str(Translated.split(' ', 1)[1])
  1731. bot.sendMessage(chat_id, '*' + Selectedlan + ' \u2192 ' + Movedlan + ':*\n' + newText, parse_mode='markdown')
  1732. except:
  1733. Translated = str(translator.translate(toTranslate, dest='en').text)
  1734. Selectedlan = str(translator.translate(toTranslate, dest='en').src).capitalize().upper()
  1735. Movedlan = str(translator.translate(toTranslate, dest='en').dest).capitalize().upper()
  1736. print(Translated)
  1737. if msg['text'].lower()[4:] == Translated.lower():
  1738. pass
  1739. else:
  1740. bot.sendMessage(chat_id, '*' + Selectedlan + ' \u2192 ' + Movedlan + ':*\n' + Translated, parse_mode='markdown')
  1741.  
  1742. #if "/portrait" in message:
  1743. # if 'private' in msg['chat']['type']:
  1744. # if 'reply_to_message' in msg:
  1745. # t = threading.Thread(target=portrait)
  1746. # t.start()
  1747. # else:
  1748. # if "True" in open(str(chat_id) + "/data/photo.txt", "r"):
  1749. # t = threading.Thread(target=portrait)
  1750. # t.start()
  1751. #def makeup():
  1752. # if 'reply_to_message' in msg:
  1753. # try:
  1754. # Bot.send_chat_action(chat_id, action=telegram.ChatAction.TYPING)
  1755. # number = message[10:]
  1756. # file_id = msg['reply_to_message']['photo'][-1]['file_id']
  1757. # filename = str(msg['reply_to_message']['from']['id']) + ".jpg"
  1758. # bot.download_file(file_id, filename)
  1759. # image = face_recognition.load_image_file(filename)
  1760. #
  1761. # # Find all facial features in all the faces in the image
  1762. # face_landmarks_list = face_recognition.face_landmarks(image)
  1763. #
  1764. # for face_landmarks in face_landmarks_list:
  1765. # pil_image = Image.fromarray(image)
  1766. # d = ImageDraw.Draw(pil_image, 'RGBA')
  1767.  
  1768. # Make the eyebrows into a nightmare
  1769. # d.polygon(face_landmarks['left_eyebrow'], fill=(68, 54, 39, 128))
  1770. # d.polygon(face_landmarks['right_eyebrow'], fill=(68, 54, 39, 128))
  1771. # d.line(face_landmarks['left_eyebrow'], fill=(68, 54, 39, 150), width=5)
  1772. # d.line(face_landmarks['right_eyebrow'], fill=(68, 54, 39, 150), width=5)
  1773. #
  1774. # # Gloss the lips
  1775. # d.polygon(face_landmarks['top_lip'], fill=(150, 0, 0, 128))
  1776. # d.polygon(face_landmarks['bottom_lip'], fill=(150, 0, 0, 128))
  1777. #3 d.line(face_landmarks['top_lip'], fill=(150, 0, 0, 64), width=8)
  1778. # d.line(face_landmarks['bottom_lip'], fill=(150, 0, 0, 64), width=8)
  1779.  
  1780. # Sparkle the eyes
  1781. # d.polygon(face_landmarks['left_eye'], fill=(255, 255, 255, 30))
  1782. # d.polygon(face_landmarks['right_eye'], fill=(255, 255, 255, 30))
  1783.  
  1784. # Apply some eyeliner
  1785. # d.line(face_landmarks['left_eye'] + [face_landmarks['left_eye'][0]], fill=(0, 0, 0, 110),
  1786. #3 width=6)
  1787. #33 d.line(face_landmarks['right_eye'] + [face_landmarks['right_eye'][0]], fill=(0, 0, 0, 110),
  1788. # width=6)
  1789.  
  1790. #pil_image.convert().save("1" + filename)
  1791. # bot.sendPhoto(chat_id, open("1" + filename, "rb"))
  1792. # os.remove(filename)
  1793. # os.remove("1" + filename)
  1794. # except:
  1795. # ()
  1796. # else:
  1797. # bot.sendMessage(chat_id, "Reply to a photo.")
  1798.  
  1799. #if "/makeup" in message:
  1800. # if 'private' in msg['chat']['type']:
  1801. # if 'reply_to_message' in msg:
  1802. # t = threading.Thread(target=makeup)
  1803. # t.start()
  1804. #else:
  1805. # if "True" in open(str(chat_id) + "/data/photo.txt", "r"):
  1806. # t = threading.Thread(target=makeup)
  1807. # t.start()
  1808.  
  1809. def detect_labels(path):
  1810. client = implicit(vision.ImageAnnotatorClient())
  1811. with io.open(path, 'rb') as image_file:
  1812. content = image_file.read()
  1813.  
  1814. image = types.Image(content=content)
  1815. response = client.label_detection(image=image)
  1816. labels = response.label_annotations
  1817. selection = ['I think this is ', "This might be ", "This could be "]
  1818. bot.sendMessage(chat_id, random.choice(selection) + str(labels[0].description), reply_to_message_id=msg['message_id'])
  1819. def detect():
  1820. if 'reply_to_message' in msg:
  1821. try:
  1822. Bot.send_chat_action(chat_id, action=telegram.ChatAction.TYPING)
  1823. number = message[10:]
  1824. file_id = msg['reply_to_message']['photo'][-1]['file_id']
  1825. filename = str(msg['reply_to_message']['from']['id']) + ".jpg"
  1826. bot.download_file(file_id, filename)
  1827. detect_labels(filename)
  1828. os.remove(filename)
  1829. os.remove("1" + filename)
  1830. except:
  1831. ()
  1832. else:
  1833. bot.sendMessage(chat_id, "Reply to a photo.")
  1834.  
  1835. if "/detect" in message:
  1836. t = threading.Thread(target=detect)
  1837. t.start()
  1838.  
  1839. def readtext(path):
  1840. client = vision.ImageAnnotatorClient()
  1841.  
  1842. # [START migration_text_detection]
  1843. with io.open(path, 'rb') as image_file:
  1844. content = image_file.read()
  1845.  
  1846. image = types.Image(content=content)
  1847.  
  1848. response = client.text_detection(image=image)
  1849. texts = response.text_annotations
  1850. if len(texts[0].description) < 100:
  1851. bot.sendMessage(chat_id, 'I read:\n*{}*'.format(texts[0].description), parse_mode='markdown', reply_to_message_id=msg['message_id'])
  1852. else:
  1853. bot.sendMessage(chat_id, 'I read:\n*{}*'.format(texts[0].description[:100]) + "\n(Text limited to 100 characters.)", parse_mode='markdown', reply_to_message_id=msg['message_id'])
  1854. def read():
  1855. if 'reply_to_message' in msg:
  1856. Bot.send_chat_action(chat_id, action=telegram.ChatAction.TYPING)
  1857. number = message[10:]
  1858. file_id = msg['reply_to_message']['photo'][-1]['file_id']
  1859. filename = str(msg['reply_to_message']['from']['id']) + ".jpg"
  1860. bot.download_file(file_id, filename)
  1861. readtext(filename)
  1862. os.remove(filename)
  1863. os.remove("1" + filename)
  1864. else:
  1865. bot.sendMessage(chat_id, "Reply to a photo.")
  1866. def play():
  1867. try:
  1868. query_string = urllib.parse.urlencode({"search_query": msg['text'][6:]})
  1869. html_content = urllib.request.urlopen("http://www.youtube.com/results?" + query_string)
  1870. search_results = re.findall(r'href=\"\/watch\?v=(.{11})', html_content.read().decode())
  1871.  
  1872. class AppURLopener(urllib.request.FancyURLopener):
  1873. version = "Chrome/60.0.3112.113"
  1874.  
  1875. opener = AppURLopener()
  1876. fp = opener.open("http://www.youtube.com/watch?v=" + search_results[0])
  1877. mybytes = fp.read()
  1878. open("text.txt", "w").write(str(mybytes))
  1879. mystr = mybytes.decode("utf8")
  1880. fp.close()
  1881. titlehtml = ',"title":"(.+?)","'
  1882. titlecompile = re.compile(titlehtml)
  1883. viewshtml = 'views-info"><div class="watch-view-count">(.+?) views</div>'
  1884. viewscompile = re.compile(viewshtml)
  1885. views = re.findall(viewscompile, mystr)
  1886. authorhtml = ',"author":"(.+?)",'
  1887. authorcompile = re.compile(authorhtml)
  1888. author = re.findall(authorcompile, mystr)
  1889. likeshtml = 'aria-label="like this video along with (.+?) other people"'
  1890. likescompile = re.compile(likeshtml)
  1891. likes = re.findall(likescompile, mystr)
  1892. dislikehtml = 'aria-label="dislike this video along with (.+?) other people"'
  1893. dislikecompile = re.compile(dislikehtml)
  1894. dislikes = re.findall(dislikecompile, mystr)
  1895. timehtml = '<strong class="watch-time-text">Published on (.+?)</strong></div>'
  1896. timecompile = re.compile(timehtml)
  1897. timevideo = re.findall(timecompile, mystr)
  1898. authorlink = '<link itemprop="url" href="http://www.youtube.com/user/(.+?)">'
  1899. authorlink2 = '<a href="/channel/(.+?)"'
  1900. authorlink2compile = re.compile(authorlink2)
  1901. authorlink2 = re.findall(authorlink2compile, mystr)
  1902. authorlinkcompile = re.compile(authorlink)
  1903. authorlink = re.findall(authorlinkcompile, mystr)
  1904. if likes == []:
  1905. likes = '0'
  1906. if dislikes == []:
  1907. dislikes = '0'
  1908. if len(str(re.findall(titlecompile, mystr))) != 25:
  1909. if len(str(re.findall(titlecompile, mystr))) > 25:
  1910. title = re.findall(titlecompile, mystr)[0][:25] + '...'
  1911. else:
  1912. title = re.findall(titlecompile, mystr)[0]
  1913. else:
  1914. title = re.findall(titlecompile, mystr)[0]
  1915. if len(author[0]) != 20:
  1916. if len(author[0]) > 25:
  1917. author = re.findall(authorcompile, mystr)[:20]
  1918. else:
  1919. author = re.findall(authorcompile, mystr)
  1920. else:
  1921. author = re.findall(authorcompile, mystr)
  1922. try:
  1923. bot.sendMessage(chat_id, '[' + title + '](' + "http://www.youtube.com/watch?v=" + search_results[0]
  1924. + ')' + '\n \u250c*Author* - [' + author[0] + '](http://www.youtube.com/user/' +
  1925. authorlink[0]
  1926. + ')\n \u251c*Views* - ' + views[0] + '\n \u251c*Date* - ' + timevideo[0]
  1927. + '\n \u251c*Likes* - \U0001f44d ' +
  1928. likes[0] + '\n \u2514*Dislikes* - \U0001f44e ' +
  1929. dislikes[0], parse_mode='markdown', disable_web_page_preview='False',
  1930. reply_to_message_id=msg['message_id'])
  1931. except:
  1932. bot.sendMessage(chat_id, '[' + title + '](' + "http://www.youtube.com/watch?v=" + search_results[0]
  1933. + ')' + '\n \u250c*Author* - [' + author[0] + '](http://www.youtube.com/user/' +
  1934. authorlink2[0]
  1935. + ')\n \u251c*Views* - ' + views[0] + '\n \u251c*Date* - ' + timevideo[0]
  1936. + '\n \u251c*Likes* - \U0001f44d ' +
  1937. likes[0] + '\n \u2514*Dislikes* - \U0001f44e ' +
  1938. dislikes[0], parse_mode='markdown', disable_web_page_preview='False',
  1939. reply_to_message_id=msg['message_id'])
  1940. except:
  1941. bot.sendMessage(chat_id, '\U0001F6AB - No results found', reply_to_message_id=msg['message_id'])
  1942. if message.startswith('/play '):
  1943. t = threading.Thread(target=play)
  1944. t.start()
  1945.  
  1946. def equalize():
  1947. if 'reply_to_message' in msg:
  1948. try:
  1949. Bot.send_chat_action(chat_id, action=telegram.ChatAction.TYPING)
  1950. number = message[10:]
  1951. file_id = msg['reply_to_message']['photo'][-1]['file_id']
  1952. filename = str(msg['reply_to_message']['from']['id']) + ".jpg"
  1953. bot.download_file(file_id, filename)
  1954. img = PIL.Image.open(filename)
  1955. convert = PIL.ImageOps.equalize(img)
  1956. convert.save("1" + filename)
  1957. bot.sendPhoto(chat_id, open("1" + filename, "rb"))
  1958. os.remove(filename)
  1959. os.remove("1" + filename)
  1960. except:
  1961. ()
  1962. else:
  1963. bot.sendMessage(chat_id, "Reply to a photo.")
  1964.  
  1965. if "/equalize" in message:
  1966. t = threading.Thread(target=equalize)
  1967. t.start()
  1968.  
  1969. def posterize():
  1970. if 'reply_to_message' in msg:
  1971. try:
  1972. Bot.send_chat_action(chat_id, action=telegram.ChatAction.TYPING)
  1973. number = message[10:]
  1974. file_id = msg['reply_to_message']['photo'][-1]['file_id']
  1975. filename = str(msg['reply_to_message']['from']['id']) + ".jpg"
  1976. bot.download_file(file_id, filename)
  1977. img = PIL.Image.open(filename)
  1978. convert = PIL.ImageOps.posterize(img, 2)
  1979. convert.save("1" + filename)
  1980. bot.sendPhoto(chat_id, open("1" + filename, "rb"))
  1981. os.remove(filename)
  1982. os.remove("1" + filename)
  1983. except:
  1984. ()
  1985. else:
  1986. bot.sendMessage(chat_id, "Reply to a photo.")
  1987.  
  1988. if "/posterize" in message:
  1989. if 'private' in msg['chat']['type']:
  1990. if 'reply_to_message' in msg:
  1991. t = threading.Thread(target=posterize)
  1992. t.start()
  1993. else:
  1994. if "True" in open(str(chat_id) + "/data/photo.txt", "r"):
  1995. t = threading.Thread(target=posterize)
  1996. t.start()
  1997.  
  1998. def invert():
  1999. if 'reply_to_message' in msg:
  2000. Bot.send_chat_action(chat_id, action=telegram.ChatAction.TYPING)
  2001. number = message[10:]
  2002. file_id = msg['reply_to_message']['photo'][-1]['file_id']
  2003. filename = str(msg['reply_to_message']['from']['id']) + ".jpg"
  2004. bot.download_file(file_id, filename)
  2005. img = PIL.Image.open(filename)
  2006. convert = PIL.ImageOps.invert(img)
  2007. convert.save("1" + filename)
  2008. bot.sendPhoto(chat_id, open("1" + filename, "rb"))
  2009. os.remove(filename)
  2010. os.remove("1" + filename)
  2011. else:
  2012. bot.sendMessage(chat_id, "Reply to a photo.")
  2013.  
  2014. if "/invert" in message:
  2015. t = threading.Thread(target=invert)
  2016. t.start()
  2017.  
  2018. def saturate():
  2019. try:
  2020. Bot.send_chat_action(chat_id, action=telegram.ChatAction.TYPING)
  2021. file_id = msg['reply_to_message']['photo'][-1]['file_id']
  2022. filename = str(msg['reply_to_message']['from']['id']) + ".jpg"
  2023. bot.download_file(file_id, filename)
  2024. img = PIL.Image.open(filename)
  2025. convert = PIL.ImageEnhance.Color(img)
  2026. img2 = convert.enhance(10)
  2027. img2.save("1" + filename)
  2028. bot.sendPhoto(chat_id, open("1" + filename, "rb"))
  2029. os.remove(filename)
  2030. os.remove("1" + filename)
  2031. except:
  2032. bot.sendMessage(chat_id, "/saturate <Amount of saturation in numbers>")
  2033.  
  2034. def captionb():
  2035. if 'reply_to_message' in msg:
  2036. try:
  2037. Bot.send_chat_action(chat_id, action=telegram.ChatAction.TYPING)
  2038. numbe = msg['text'][10:]
  2039. size = numbe.split("::")[1]
  2040. number = numbe.split("::", 1)[0]
  2041. file_id = msg['reply_to_message']['photo'][-1]['file_id']
  2042. filename = str(msg['reply_to_message']['from']['id']) + ".jpg"
  2043. bot.download_file(file_id, filename)
  2044. img = PIL.Image.open(filename)
  2045. draw = PIL.ImageDraw.Draw(img)
  2046. w, h = img.size
  2047. font = ImageFont.truetype("comic.ttf", int(size))
  2048. text_w, text_h = draw.textsize(number, font)
  2049. draw.text(((w - text_w) // 2, h - text_h), number, (0, 0, 0), font=font)
  2050. img.save("1" + filename)
  2051. bot.sendPhoto(chat_id, open("1" + filename, "rb"))
  2052. os.remove(filename)
  2053. os.remove("1" + filename)
  2054. except:
  2055. ()
  2056. else:
  2057. bot.sendMessage(chat_id, "Reply to a photo.")
  2058.  
  2059. def captionerror():
  2060. bot.sendMessage(chat_id, "/caption text::textsize (in numbers)")
  2061.  
  2062. def captionerrorb():
  2063. bot.sendMessage(chat_id, "/captionb text::textsize (in numbers)")
  2064. if message == "/caption":
  2065. if 'private' in msg['chat']['type']:
  2066. if 'reply_to_message' in msg:
  2067. t = threading.Thread(target=captionerror)
  2068. t.start()
  2069. else:
  2070. if "True" in open(str(chat_id) + "/data/photo.txt", "r"):
  2071. t = threading.Thread(target=captionerror)
  2072. t.start()
  2073. if "/caption " in message:
  2074. if 'private' in msg['chat']['type']:
  2075. if 'reply_to_message' in msg:
  2076. t = threading.Thread(target=caption)
  2077. t.start()
  2078. else:
  2079. if "True" in open(str(chat_id) + "/data/photo.txt", "r"):
  2080. if 'reply_to_message' in msg:
  2081. t = threading.Thread(target=caption)
  2082. t.start()
  2083. else:
  2084. bot.sendMessage(chat_id, "Please reply to a photo.")
  2085. if "/rblur" in message:
  2086. if 'private' in msg['chat']['type']:
  2087. if 'reply_to_message' in msg:
  2088. t = threading.Thread(target=rblur)
  2089. t.start()
  2090. else:
  2091. if "True" in open(str(chat_id) + "/data/photo.txt", "r"):
  2092. if 'reply_to_message' in msg:
  2093. t = threading.Thread(target=rblur)
  2094. t.start()
  2095. else:
  2096. bot.sendMessage(chat_id, "Please reply to a photo.")
  2097. def weather():
  2098. try:
  2099. weather = Weather(unit=Unit.FAHRENHEIT)
  2100. weatherc = Weather(unit=Unit.CELSIUS)
  2101. locationinfo = msg['text'].lower()[9:]
  2102. location = weather.lookup_by_location(locationinfo)
  2103. locationc = weatherc.lookup_by_location(locationinfo)
  2104. condition = location.condition()
  2105. conditionc = locationc.condition()
  2106. weatheremoji = ""
  2107. if str(condition.text().lower()) == "tornado":
  2108. weatheremoji = "\U0001F32A"
  2109. elif str(condition.text().lower()) == "showers":
  2110. weatheremoji = "\U0001F327"
  2111. elif str(condition.text().lower()) == "scattered showers":
  2112. weatheremoji = "\U0001F327"
  2113. elif str(condition.text().lower()) == "rain":
  2114. weatheremoji = "\U0001F327"
  2115. elif str(condition.text().lower()) == "mixed rain and hail":
  2116. weatheremoji = "\U0001F327"
  2117. elif str(condition.text().lower()) == "hot":
  2118. weatheremoji = "\U0001F525"
  2119. elif str(condition.text().lower()) == "tropical storm":
  2120. weatheremoji = "\U0001F300"
  2121. elif str(condition.text().lower()) == "hurricane":
  2122. weatheremoji = "\U0001F300"
  2123. elif str(condition.text().lower()) == "thunderstorms":
  2124. weatheremoji = "\U0001F329"
  2125. elif str(condition.text().lower()) == "isolated thunderstorms":
  2126. weatheremoji = "\U0001F329"
  2127. elif str(condition.text().lower()) == "scattered thunderstorms":
  2128. weatheremoji = "\U0001F329"
  2129. elif str(condition.text().lower()) == "mixed rain and snow":
  2130. weatheremoji = "\U0001F328"
  2131. elif str(condition.text().lower()) == "mixed rain and sleet":
  2132. weatheremoji = "\U0001F328"
  2133. elif str(condition.text().lower()) == "mixed snow and sleet":
  2134. weatheremoji = "\U0001F328"
  2135. elif str(condition.text().lower()) == "freezing drizzle":
  2136. weatheremoji = "\U00002744\U0001F4A7"
  2137. elif str(condition.text().lower()) == "drizzle":
  2138. weatheremoji = "\U0001F4A7"
  2139. elif str(condition.text().lower()) == "freezing rain":
  2140. weatheremoji = "\U00002744\U0001F327"
  2141. elif str(condition.text().lower()) == "snow flurries":
  2142. weatheremoji = "\U0001F328"
  2143. elif str(condition.text().lower()) == "heavy snow":
  2144. weatheremoji = "\U0001F328"
  2145. elif str(condition.text().lower()) == "scattered snow showers":
  2146. weatheremoji = "\U0001F328"
  2147. elif str(condition.text().lower()) == "blowing snow":
  2148. weatheremoji = "\U0001F328"
  2149. elif str(condition.text().lower()) == "snow":
  2150. weatheremoji = "\U0001F328"
  2151. elif str(condition.text().lower()) == "sleet":
  2152. weatheremoji = "\U0001F328"
  2153. elif str(condition.text().lower()) == "hail":
  2154. weatheremoji = "\U0001F327"
  2155. elif str(condition.text().lower()) == "dust":
  2156. weatheremoji = "\U0001F32B"
  2157. elif str(condition.text().lower()) == "foggy":
  2158. weatheremoji = "\U0001F32B"
  2159. elif str(condition.text().lower()) == "haze":
  2160. weatheremoji = "\U0001F32B"
  2161. elif str(condition.text().lower()) == "smoky":
  2162. weatheremoji = "\U0001F32B"
  2163. elif str(condition.text().lower()) == "blustery":
  2164. weatheremoji = "\U0001F4A8"
  2165. elif str(condition.text().lower()) == "windy":
  2166. weatheremoji = "\U0001F4A8"
  2167. elif str(condition.text().lower()) == "cold":
  2168. weatheremoji = "\U00002744"
  2169. elif str(condition.text().lower()) == "cloudy":
  2170. weatheremoji = "\U00002601"
  2171. elif str(condition.text().lower()) == "partly cloudy":
  2172. weatheremoji = "\U0001F325"
  2173. elif str(condition.text().lower()) == "thundershowers":
  2174. weatheremoji = "\U000026C8"
  2175. elif str(condition.text().lower()) == "snow showers":
  2176. weatheremoji = "\U0001F328"
  2177. elif str(condition.text().lower()) == "not available":
  2178. weatheremoji = "\U0000274C"
  2179. elif str(condition.text().lower()) == "mostly cloudy (night)":
  2180. weatheremoji = "\U00002601"
  2181. elif str(condition.text().lower()) == "mostly cloudy (day)":
  2182. weatheremoji = "\U000026C5"
  2183. elif str(condition.text().lower()) == "mostly cloudy":
  2184. weatheremoji = "\U000026C5"
  2185. elif str(condition.text().lower()) == "partly cloudy":
  2186. weatheremoji = "\U000026C5"
  2187. elif str(condition.text().lower()) == "partly cloudy (day)":
  2188. weatheremoji = "\U000026C5"
  2189. elif str(condition.text().lower()) == "partly cloudy (night)":
  2190. weatheremoji = "\U00002601"
  2191. elif str(condition.text().lower()) == "clear (night)":
  2192. weatheremoji = "\U0001F315"
  2193. elif str(condition.text().lower()) == "clear":
  2194. weatheremoji = "\U0001F31E"
  2195. elif str(condition.text().lower()) == "sunny":
  2196. weatheremoji = "\U0001F31E"
  2197. elif str(condition.text().lower()) == "fair (day)":
  2198. weatheremoji = "\U000026C5"
  2199. elif str(condition.text().lower()) == "fair (night)":
  2200. weatheremoji = "\U00002601"
  2201. val = int((float(location.wind()['direction']) / 22.5) + .5)
  2202. arr = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"]
  2203. direction = str(arr[(val % 16)])
  2204. bot.sendMessage(chat_id, "*The weather in " + locationinfo.title() + ":*\n\u250c" + condition.text() + " " + weatheremoji + "\n\u251c" + condition.temp() + "\u00b0F (" + conditionc.temp() + "\u00b0C)\n\u251cWindspeed of " + location.wind()["speed"] + " MPH(" + direction + ")\n\u251cSunset at " + location.astronomy()['sunset'] + "\n\u2514Sunrise at " + location.astronomy()['sunrise'], parse_mode="markdown")
  2205. except:
  2206. bot.sendMessage(chat_id, "I could not find the place you are looking for. Perhaps being more specific?")
  2207. if "/weather " in message:
  2208. if "hell" in message:
  2209. bot.sendMessage(chat_id,
  2210. "*The weather in Hell:*\n\u250cHot \U0001F525\n\u251c187\u00b0F (86\u00b0C)\n\u2514Windspeed of 73 MPH(NW)", parse_mode="markdown")
  2211. else:
  2212. t = threading.Thread(target=weather)
  2213. t.start()
  2214. if "/bitcoin" in message:
  2215. bot.sendMessage(chat_id, "The current price of bitcoin is *$" + str(Bitfinex().get_current_price()) + "*", parse_mode="markdown")
  2216. if message == "/captionb":
  2217. if 'private' in msg['chat']['type']:
  2218. if 'reply_to_message' in msg:
  2219. t = threading.Thread(target=captionerrorb)
  2220. t.start()
  2221. else:
  2222. if "True" in open(str(chat_id) + "/data/photo.txt", "r"):
  2223. t = threading.Thread(target=captionerrorb)
  2224. t.start()
  2225.  
  2226. if message.startswith("/captionb "):
  2227. if 'private' in msg['chat']['type']:
  2228. if 'reply_to_message' in msg:
  2229. t = threading.Thread(target=captionb)
  2230. t.start()
  2231. else:
  2232. if "True" in open(str(chat_id) + "/data/photo.txt", "r"):
  2233. if 'reply_to_message' in msg:
  2234. t = threading.Thread(target=captionb)
  2235. t.start()
  2236. else:
  2237. bot.sendMessage(chat_id, "Please reply to a photo.")
  2238. if message == "/saturate":
  2239. if 'private' in msg['chat']['type']:
  2240. if 'reply_to_message' in msg:
  2241. t = threading.Thread(target=saturate)
  2242. t.start()
  2243. else:
  2244. if "True" in open(str(chat_id) + "/data/photo.txt", "r"):
  2245. if 'reply_to_message' in msg:
  2246. t = threading.Thread(target=saturate)
  2247. t.start()
  2248. else:
  2249. bot.sendMessage(chat_id, "Please respond to a photo.")
  2250. if "/contour" in message:
  2251. if 'private' in msg['chat']['type']:
  2252. if 'reply_to_message' in msg:
  2253. t = threading.Thread(target=contour)
  2254. t.start()
  2255. else:
  2256. if "True" in open(str(chat_id) + "/data/photo.txt", "r"):
  2257. if 'reply_to_message' in msg:
  2258. t = threading.Thread(target=contour)
  2259. t.start()
  2260. else:
  2261. bot.sendMessage(chat_id, "Please respond to a photo.")
  2262. if "/blur " in message:
  2263. if 'private' in msg['chat']['type']:
  2264. if 'reply_to_message' in msg:
  2265. t = threading.Thread(target=blur)
  2266. t.start()
  2267. else:
  2268. if "True" in open(str(chat_id) + "/data/photo.txt", "r"):
  2269. if 'reply_to_message' in msg:
  2270. t = threading.Thread(target=blur)
  2271. t.start()
  2272. else:
  2273. bot.sendMessage(chat_id, "Please respond to a photo.")
  2274. if "/sharpen" in message:
  2275. if 'private' in msg['chat']['type']:
  2276. if 'reply_to_message' in msg:
  2277. t = threading.Thread(target=sharpen)
  2278. t.start()
  2279. else:
  2280. if "True" in open(str(chat_id) + "/data/photo.txt", "r"):
  2281. if 'reply_to_message' in msg:
  2282. t = threading.Thread(target=sharpen)
  2283. t.start()
  2284. else:
  2285. bot.sendMessage(chat_id, "Please respond to a photo.")
  2286. if message.startswith("/saturate "):
  2287. if 'private' in msg['chat']['type']:
  2288. if 'reply_to_message' in msg:
  2289. t = threading.Thread(target=saturatee)
  2290. t.start()
  2291. else:
  2292. if "True" in open(str(chat_id) + "/data/photo.txt", "r"):
  2293. if 'reply_to_message' in msg:
  2294. t = threading.Thread(target=saturatee)
  2295. t.start()
  2296. else:
  2297. bot.sendMessage(chat_id, "Please respond to a photo.")
  2298.  
  2299. def toggle():
  2300. if "True" in open(str(chat_id) + "/data/jokes.txt", "r"):
  2301. Jks = "*On*"
  2302. if "False" in open(str(chat_id) + "/data/jokes.txt", "r"):
  2303. Jks = "*Off*"
  2304. if "True" in open(str(chat_id) + "/data/8ball.txt", "r"):
  2305. eB = "*On*"
  2306. if "False" in open(str(chat_id) + "/data/8ball.txt", "r"):
  2307. eB = "*Off*"
  2308. if "True" in open(str(chat_id) + "/data/roll.txt", "r"):
  2309. rL = "*On*"
  2310. if "False" in open(str(chat_id) + "/data/roll.txt", "r"):
  2311. rL = "*Off*"
  2312. if "True" in open(str(chat_id) + "/data/lock.txt", "r"):
  2313. gL = "*On*"
  2314. if "False" in open(str(chat_id) + "/data/lock.txt", "r"):
  2315. gL = "*Off*"
  2316. if "False" in open(str(chat_id) + "/data/link.txt", "r"):
  2317. nolink = "*Off*"
  2318. if "True" in open(str(chat_id) + "/data/link.txt", "r"):
  2319. nolink = "*On*"
  2320. if "True" in open(str(chat_id) + "/data/pong.txt", "r"):
  2321. pL = "*On*"
  2322. if "False" in open(str(chat_id) + "/data/pong.txt", "r"):
  2323. pL = "*Off*"
  2324. if "True" in open(str(chat_id) + "/data/mm.txt", "r"):
  2325. mL = "*On*"
  2326. if "False" in open(str(chat_id) + "/data/mm.txt", "r"):
  2327. mL = "*Off*"
  2328. if "True" in open(str(chat_id) + "/data/antibot.txt", "r"):
  2329. aB = "*On*"
  2330. if "False" in open(str(chat_id) + "/data/antibot.txt", "r"):
  2331. aB = "*Off*"
  2332. if "True" in open(str(chat_id) + "/data/flip.txt", "r"):
  2333. fL = "*On*"
  2334. if "False" in open(str(chat_id) + "/data/flip.txt", "r"):
  2335. fL = "*Off*"
  2336. if "True" in open(str(chat_id) + "/data/tts.txt", "r"):
  2337. tTS = "*On*"
  2338. if "False" in open(str(chat_id) + "/data/tts.txt", "r"):
  2339. tTS = "*Off*"
  2340. if "True" in open(str(chat_id) + "/data/photo.txt", "r"):
  2341. pT = "*On*"
  2342. if "False" in open(str(chat_id) + "/data/photo.txt", "r"):
  2343. pT = "*Off*"
  2344. if "True" in open(str(chat_id) + "/data/urban.txt", "r"):
  2345. uD = "*Off*"
  2346. if "False" in open(str(chat_id) + "/data/urban.txt", "r"):
  2347. uD = "*On*"
  2348. bot.sendMessage(chat_id,
  2349. "Jokes: " + Jks + "\nMagic 8Ball: " + eB + "\nRolling: " + rL + "\nInvite Links: " + nolink + "\nGroup Lock: " + gL + "\nAntibot: " + aB + "\nPhoto edit: " + pT + '\nUrban Dict: ' + uD + '\nTTS: ' + tTS, parse_mode='markdown')
  2350. def roll2():
  2351. edited = telepot.message_identifier(bot.sendMessage(chat_id, 'Rolling two dice...'))
  2352. time.sleep(0.7)
  2353. rollrandom = str(random.randint(1, 6))
  2354. rollrandom2 = str(random.randint(1, 6))
  2355. bot.editMessageText(edited, "*" + str(rollrandom) + "* and a", parse_mode="markdown")
  2356. time.sleep(0.5)
  2357. bot.editMessageText(edited, "*" + str(rollrandom) + "*" + " and a " + "*" + str(rollrandom2) + "*",
  2358. parse_mode="markdown")
  2359.  
  2360. def roll1():
  2361. edited = telepot.message_identifier(bot.sendMessage(chat_id, 'Rolling a single dice'))
  2362. time.sleep(0.7)
  2363. bot.editMessageText(edited, "*" + str(random.randint(1, 6)) + "*", parse_mode="markdown")
  2364.  
  2365. if message == "/roll":
  2366. if isPrivateMessage == True:
  2367. t = threading.Thread(target=roll1)
  2368. t.start()
  2369. else:
  2370. if "True" in open(str(chat_id) + "/data/roll.txt", "r"):
  2371. t = threading.Thread(target=roll1)
  2372. t.start()
  2373. if "/roll2" in message:
  2374. if isPrivateMessage == True:
  2375. if 'help' in message:
  2376. pass
  2377. else:
  2378. t = threading.Thread(target=roll1)
  2379. t.start()
  2380. else:
  2381. if "True" in open(str(chat_id) + "/data/roll.txt", "r"):
  2382. t = threading.Thread(target=roll1)
  2383. t.start()
  2384. if "/id" in message:
  2385. try:
  2386. bot.sendMessage(chat_id, msg['reply_to_message']['from']['id'])
  2387. except:
  2388. bot.sendMessage(chat_id, messageFromID)
  2389. if "/chatid" in message:
  2390. bot.sendMessage(chat_id, chat_id)
  2391. if "/com" in message:
  2392. if isPrivateMessage == True:
  2393. bot.sendMessage(chat_id, '''*Admin/Group Commands:*\n\u2022/leaderboard\n\u2022/kick\n\u2022/kickme\n\u2022/ban\n\u2022/scramble\n\u2022/unban\n\u2022/mute\n\u2022/unmute\n\u2022/link\n\u2022/addcom\n\u2022/delcom\n\u2022/unrestrict\n\u2022/voice\n\u2022/arabic\n\u2022/blacklist\n\u2022/nomedia\n\u2022/lock\n\u2022/antibot\n\u2022/gt\n\u2022/eb\n\u2022/photo\n\u2022/jt\n\u2022/rt\n\u2022/toggles\n\u2022/pin\n\u2022/color (/colour)\n\u2022/greet\n\u2022/title\n\u2022/limit\n\u2022/promote\n\u2022/demote\n\u2022/warn\n\u2022/reset\n\n*Universal commands (works in group and pm):*\n\u2022/bw\n\u2022/swirl\n\u2022/saturate\n\u2022/play\n\u2022/tts\n\u2022/caption\n\u2022/captionb\n\u2022/jokes\n\u2022/time\n\u2022/totalmessages\n\u2022/ud\n\u2022/callme\n\u2022/8ball\n\u2022/polaroid\n\u2022/sharpen\n\u2022/posterize\n\u2022/invert\n\u2022/contour\n\u2022/rblur\n\u2022/blur\n\n_if you need help on a command, type the command and then help after (/bw help) Note: A lot of the commands don't have a help response YET, sorry!_''', parse_mode='markdown')
  2394. else:
  2395. bot.sendMessage(chat_id, "To view the list of commands, please use this command in PMs. It's a long list.")
  2396. if message == "/kickme":
  2397. try:
  2398. bot.kickChatMember(chat_id, messageFromID)
  2399. bot.unbanChatMember(chat_id, messageFromID)
  2400. except:
  2401. pass
  2402. def executeCommand():
  2403. customCommand = str(open(str(chat_id) + "/data/c" + str(message).replace("/", "slas12") + ".txt", "r").read())
  2404. if os.path.isfile(str(chat_id) + '/data/counting' + str(message).replace("/", "slas12") + '.txt') == True:
  2405. minus = int(str(open(str(chat_id) + '/data/counting' + str(message).replace('/', 'slas12') + '.txt', "r+").readlines()).replace("[", "").replace("'",
  2406. "").replace(
  2407. "]", "")) + 1
  2408. open(chat_id + '/data/counting' + str(message).replace('/', 'slas12') + '.txt', "w").write(str(minus))
  2409. counter = str(open(str(chat_id) + '/data/counting' + str(message).replace('/', 'slas12') + '.txt', 'r').read())
  2410. else:
  2411. counter = ""
  2412. randomUser = 'soon'
  2413. if 'reply_to_message' in msg:
  2414. if os.path.isfile("data/n" + str(msg['reply_to_message']['from']['id']) + ".txt") == False:
  2415. repliedName = str(msg['reply_to_message']['from']['first_name'][:15])
  2416. else:
  2417. repliedName = str(open("data/n" + str(msg['reply_to_message']['from']['id']) + ".txt").read())
  2418.  
  2419. if 'username' in msg['reply_to_message']['from']:
  2420. repliedUsername = "@" + str(msg['reply_to_message']['from']['username'])
  2421. else:
  2422. repliedUsername = '@None'
  2423. else:
  2424. if os.path.isfile("data/n" + str(messageFromID) + ".txt") == False:
  2425. repliedName = str(msg['from']['first_name'][:15])
  2426. else:
  2427. repliedName = str(open("data/n" + str(messageFromID) + ".txt").read())
  2428. if 'username' in msg['from']:
  2429. repliedUsername = "@" + str(msg['from']['username'])
  2430. else:
  2431. repliedUsername = '@None'
  2432. if os.path.isfile("data/n" + str(messageFromID) + ".txt") == False:
  2433. owningName = str(msg['from']['first_name'][:15])
  2434. else:
  2435. owningName = str(open("data/n" + str(messageFromID) + ".txt").read())
  2436. if 'username' in msg['from']:
  2437. owningUsername = str(msg['from']['username'])
  2438. else:
  2439. owningUsername = '@None'
  2440.  
  2441. workedOut = str(customCommand).replace('$n', str(owningName)).replace('$u', str(owningUsername)).replace('$rn',
  2442. repliedName).replace(
  2443. '$ru', str(repliedUsername)).replace('$admin', '').replace('$c', str(counter))
  2444.  
  2445. if '$admin' in customCommand:
  2446. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  2447. bot.sendMessage(chat_id, str(workedOut), parse_mode='markdown')
  2448. else:
  2449. if str(messageFromID) in open(str(chat_id) + "/data/admin.txt", "r").read():
  2450. bot.sendMessage(chat_id, str(workedOut), parse_mode='markdown')
  2451. else:
  2452. bot.sendMessage(chat_id, str(workedOut), parse_mode='markdown')
  2453. #if os.path.isfile(str(chat_id) + "/data/c" + str(message).replace("/", "slas12") + ".txt") == True:
  2454. # stickerExecute = False
  2455. # t = threading.Thread(target=executeCommand)
  2456. # t.start()
  2457. if '/permaban' in message:
  2458. bot.sendMessage(chat_id, "Don't worry! @spoon is working on this right now, just give it time.")
  2459. def admincom():
  2460. if "/color" in message:
  2461. if "green" in message:
  2462. open(str(chat_id) + "/data/imagecolor.txt", "w").write("green")
  2463. open(str(chat_id) + "/data/textcolor.txt", "w").write("black")
  2464. bot.sendMessage(chat_id, "Color set to green.")
  2465. elif "red" in message:
  2466. open(str(chat_id) + "/data/imagecolor.txt", "w").write("red")
  2467. open(str(chat_id) + "/data/textcolor.txt", "w").write("black")
  2468. bot.sendMessage(chat_id, "Color set to red.")
  2469. elif "blue" in message:
  2470. open(str(chat_id) + "/data/imagecolor.txt", "w").write("blue")
  2471. open(str(chat_id) + "/data/textcolor.txt", "w").write("black")
  2472. bot.sendMessage(chat_id, "Color set to blue.")
  2473. elif "black" in message:
  2474. open(str(chat_id) + "/data/imagecolor.txt", "w").write("black")
  2475. open(str(chat_id) + "/data/textcolor.txt", "w").write("white")
  2476. bot.sendMessage(chat_id, "Color set to black.")
  2477. elif "white" in message:
  2478. open(str(chat_id) + "/data/imagecolor.txt", "w").write("white")
  2479. open(str(chat_id) + "/data/textcolor.txt", "w").write("black")
  2480. bot.sendMessage(chat_id, "Color set to white.")
  2481. elif "orange" in message:
  2482. open(str(chat_id) + "/data/imagecolor.txt", "w").write("orange")
  2483. open(str(chat_id) + "/data/textcolor.txt", "w").write("black")
  2484. bot.sendMessage(chat_id, "Color set to orange.")
  2485. elif "yellow" in message:
  2486. open(str(chat_id) + "/data/imagecolor.txt", "w").write("yellow")
  2487. open(str(chat_id) + "/data/textcolor.txt", "w").write("black")
  2488. bot.sendMessage(chat_id, "Color set to yellow.")
  2489. elif "gold" in message:
  2490. open(str(chat_id) + "/data/imagecolor.txt", "w").write("yellow")
  2491. open(str(chat_id) + "/data/textcolor.txt", "w").write("black")
  2492. bot.sendMessage(chat_id, "Color set to gold.")
  2493. elif "pink" in message:
  2494. open(str(chat_id) + "/data/imagecolor.txt", "w").write("pink")
  2495. open(str(chat_id) + "/data/textcolor.txt", "w").write("black")
  2496. bot.sendMessage(chat_id, "Color set to pink.")
  2497. elif "purple" in message:
  2498. open(str(chat_id) + "/data/imagecolor.txt", "w").write("purple")
  2499. open(str(chat_id) + "/data/textcolor.txt", "w").write("white")
  2500. bot.sendMessage(chat_id, "Color set to purple.")
  2501. if "/colour" in message:
  2502. if "green" in message:
  2503. open(str(chat_id) + "/data/imagecolor.txt", "w").write("green")
  2504. open(str(chat_id) + "/data/textcolor.txt", "w").write("black")
  2505. bot.sendMessage(chat_id, "Colour set to green.")
  2506. elif "red" in message:
  2507. open(str(chat_id) + "/data/imagecolor.txt", "w").write("red")
  2508. open(str(chat_id) + "/data/textcolor.txt", "w").write("black")
  2509. bot.sendMessage(chat_id, "Colour set to red.")
  2510. elif "blue" in message:
  2511. open(str(chat_id) + "/data/imagecolor.txt", "w").write("blue")
  2512. open(str(chat_id) + "/data/textcolor.txt", "w").write("black")
  2513. bot.sendMessage(chat_id, "Colour set to blue.")
  2514. elif "black" in message:
  2515. open(str(chat_id) + "/data/imagecolor.txt", "w").write("black")
  2516. open(str(chat_id) + "/data/textcolor.txt", "w").write("white")
  2517. bot.sendMessage(chat_id, "Colour set to black.")
  2518. elif "white" in message:
  2519. open(str(chat_id) + "/data/imagecolor.txt", "w").write("white")
  2520. open(str(chat_id) + "/data/textcolor.txt", "w").write("black")
  2521. bot.sendMessage(chat_id, "Colour set to white.")
  2522. elif "orange" in message:
  2523. open(str(chat_id) + "/data/imagecolor.txt", "w").write("orange")
  2524. open(str(chat_id) + "/data/textcolor.txt", "w").write("black")
  2525. bot.sendMessage(chat_id, "Colour set to orange.")
  2526. elif "yellow" in message:
  2527. open(str(chat_id) + "/data/imagecolor.txt", "w").write("yellow")
  2528. open(str(chat_id) + "/data/textcolor.txt", "w").write("black")
  2529. bot.sendMessage(chat_id, "Colour set to yellow.")
  2530. elif "gold" in message:
  2531. open(str(chat_id) + "/data/imagecolor.txt", "w").write("yellow")
  2532. open(str(chat_id) + "/data/textcolor.txt", "w").write("black")
  2533. bot.sendMessage(chat_id, "Colour set to gold.")
  2534. elif "pink" in message:
  2535. open(str(chat_id) + "/data/imagecolor.txt", "w").write("pink")
  2536. open(str(chat_id) + "/data/textcolor.txt", "w").write("black")
  2537. bot.sendMessage(chat_id, "Colour set to pink.")
  2538. elif "purple" in message:
  2539. open(str(chat_id) + "/data/imagecolor.txt", "w").write("purple")
  2540. open(str(chat_id) + "/data/textcolor.txt", "w").write("white")
  2541. bot.sendMessage(chat_id, "Colour set to purple.")
  2542. if message.startswith('/addcom '):
  2543. if os.path.isfile(str(chat_id) + "/data/c" + str(message[8:]) + ".txt") == False:
  2544. if "/" in message[8:]:
  2545. command = message[8:].replace("/", "slas12")
  2546. else:
  2547. command = message[8:]
  2548. open(str(chat_id) + "/data/c" + str(command).split("::")[0] + ".txt", "w").write("")
  2549. open(str(chat_id) + "/data/commandlist.txt", "a").write(str(command) + "\n")
  2550. open(str(chat_id) + "/data/c" + str(command).split("::")[0] + ".txt", "w").write(str(msg['text'][8:]).split("::")[1])
  2551. if '$c' in str(msg['text']):
  2552. open(str(chat_id) + '/data/counting' + str(command).split('::')[0] + '.txt', 'w').write('0')
  2553. bot.sendMessage(chat_id, "Command added.")
  2554. else:
  2555. bot.sendMessage(chat_id, "This command is already added.")
  2556. if message == "/addcom":
  2557. bot.sendMessage(chat_id, "Example: /addcom /punch::$rn has been punched by $n!\n`spoon has been punched by fork!`\n\nSeperate with ::\n$u = senders username\n$ru = replied user's username (falls back to sender username)\n$n = senders name\n$rn = replied user's name (fallback)\n$c = a counter that adds 1 every time your command is used\n$admin = makes it an admin only command (put this anywhere after the ::, it'll be removed after the fact)", parse_mode='markdown')
  2558. if "/delcom " in message:
  2559. if os.path.isfile(str(chat_id) + "/data/c" + str(message[8:]).replace("/", "slas12") + ".txt") == True:
  2560. os.remove(str(chat_id) + "/data/c" + str(message[8:]).replace("/", "slas12") + ".txt")
  2561. with open(str(chat_id) + "/data/commandlist.txt", "r+") as f:
  2562. t = f.read()
  2563. f.seek(0)
  2564. for line in t.split('\n'):
  2565. if line != str(str(message[8:]).replace("/", "slas12").lower()):
  2566. f.write(line + '\n')
  2567. f.truncate()
  2568. bot.sendMessage(chat_id, "Command deleted.")
  2569. else:
  2570. bot.sendMessage(chat_id, "This command is not added.")
  2571. if "/limit " in message:
  2572. if re.search('[a-zA-Z]', message[7:]):
  2573. bot.sendMessage(chat_id, "The time limit can not be a letter.")
  2574. else:
  2575. open(str(chat_id) + "/data/gamelimit.txt", "w").write(message[7:])
  2576. bot.sendMessage(chat_id, "Game time limit set to " + message[7:] + " second(s)")
  2577. if "/admincom" in message:
  2578. bot.sendMessage(chat_id, "Admin Commands:\n/greet (change greet type)\n/limit (for games)\n/promote and /demote\n/ban and /unban\n/kick\n/addcom and /delcom (add custom commands)\n/mute and /unmute\n/byebot (Makes the bot leave the group)\n/photo\n/wel (Toggles welcome message)\n/eb (Toggles 8ball)\n/jt (Toggles jokes)\n/rt (Toggles rolling)\n/gt (Toggles games)\n/reset (Removes warns)\n/end (Ends current game)\n/toggles (Shows whats on and off, some are fillers)\n/limit (Set's game time limit)")
  2579. if "/end" in message:
  2580. if "inprogress" in open(str(chat_id) + "/data/scramble.txt", "r").read():
  2581. bot.sendMessage(chat_id, str(msg['from']['first_name']) + " reset the game. The word was " + open(
  2582. str(chat_id) + "/data/word.txt", "r").read())
  2583. open(str(chat_id) + "/data/scramble.txt", "w").write("False")
  2584. if "inprogress" in open(str(chat_id) + "/data/state.txt", "r").read():
  2585. bot.sendMessage(chat_id, str(msg['from']['first_name']) + " reset the game. The state was " + open(
  2586. str(chat_id) + "/data/statename.txt", "r").read())
  2587. open(str(chat_id) + "/data/state.txt", "w").write("False")
  2588. if "inprogress" in open(str(chat_id) + "/data/type.txt", "r").read():
  2589. bot.sendMessage(chat_id, str(msg['from']['first_name']) + " reset the game. The word was " + open(
  2590. str(chat_id) + "/data/typeword.txt", "r").read())
  2591. open(str(chat_id) + "/data/type.txt", "w").write("False")
  2592. def dell():
  2593. print(messageID)
  2594. if 'reply_to_message' in msg:
  2595. telegram.Bot.deleteMessage(self=Bot, chat_id=chat_id,
  2596. message_id=msg['reply_to_message']['message_id'])
  2597. telegram.Bot.deleteMessage(self=Bot, chat_id=chat_id, message_id=messageID)
  2598. else:
  2599. telegram.Bot.deleteMessage(self=Bot, chat_id=chat_id, message_id=messageID)
  2600. def dell2():
  2601. bot.sendMessage(chat_id, 'Deleting all of this users messages...')
  2602. with open(str(chat_id) + '/messages/msgid' + str(msg['reply_to_message']['from']['id']) + '.dat', 'r') as f:
  2603. for line in reversed(list(f)):
  2604. try:
  2605.  
  2606. telegram.Bot.deleteMessage(self=Bot, chat_id=chat_id, message_id=line)
  2607. except:
  2608. pass
  2609. if 'str' in line:
  2610. open(str(chat_id) + '/messages/msgid' + str(msg['reply_to_message']['from']['id']) + '.dat',
  2611. 'w').write("")
  2612. break
  2613. #telegram.Bot.deleteMessage(self=Bot, chat_id=chat_id, message_id=messageID)
  2614. open(str(chat_id) + '/messages/msgid' + str(msg['reply_to_message']['from']['id']) + '.dat',
  2615. 'w').write("")
  2616. if message.startswith("/del"):
  2617. if message.startswith("/delcom"):
  2618. ()
  2619. elif message.startswith('/delall'):
  2620. pass
  2621. else:
  2622. t = threading.Thread(target=dell)
  2623. t.start()
  2624. if message.startswith("/delall"):
  2625. if message.startswith("/delcom"):
  2626. ()
  2627. else:
  2628. t = threading.Thread(target=dell2)
  2629. t.start()
  2630. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  2631. if "/promote" in message:
  2632. if msg['reply_to_message']['from']['id'] == botID:
  2633. bot.sendMessage(chat_id, "Uhh I don't need to be admin of myself lol")
  2634. else:
  2635. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  2636. bot.sendMessage(chat_id,
  2637. "You're admin of the group, you already have access to my commands.")
  2638. else:
  2639. if str(msg['reply_to_message']['from']['id']) in open(str(chat_id) + "/data/admin.txt").read():
  2640. bot.sendMessage(chat_id, usersName + " is already an admin. To demote, type /demote")
  2641. else:
  2642. open(str(chat_id) + "/data/admin.txt", "a").write(str(msg['reply_to_message']['from']['id']) + "\n")
  2643. bot.sendMessage(chat_id, str(msg['reply_to_message']['from']['first_name']) + " has been promoted")
  2644. if "/demote" in message:
  2645. print(str(chat_id) + '/data/admin.txt')
  2646. if str(msg['reply_to_message']['from']['id']) in open(str(chat_id) + "/data/admin.txt").read():
  2647. with open(str(chat_id) + "/data/admin.txt", "r+") as f:
  2648. t = f.read()
  2649. f.seek(0)
  2650. for line in t.split('\n'):
  2651. if line != str(msg['reply_to_message']['from']['id']):
  2652. f.write(line + '\n')
  2653. f.truncate()
  2654. bot.sendMessage(chat_id, usersName + " has been demoted.")
  2655. else:
  2656. bot.sendMessage(chat_id, usersName + " isn't promoted.")
  2657. def bantimer():
  2658. timer = int(str(open(str(chat_id) + "/data/bantimer" + str(msg['reply_to_message']['from']['id']) + ".txt", "r").read())) * 60
  2659. time.sleep(timer)
  2660. bot.restrictChatMember(chat_id, msg['reply_to_message']['from']['id'], can_send_messages=True,
  2661. can_add_web_page_previews=True, can_send_media_messages=True,
  2662. can_send_other_messages=True)
  2663. bot.sendMessage(chat_id, usersName + " has been unbanned.", reply_to_message_id=msg['message_id'])
  2664. bot.unbanChatMember(chat_id, msg['reply_to_message']['from']['id'])
  2665. if message.startswith('/unblacklist '):
  2666. bot.sendMessage(chat_id, 'Word removed from list!')
  2667. f = open(str(chat_id) + '/data/blacklisted.txt', 'r')
  2668. read = f.readlines()
  2669. f.close()
  2670. name = str(msg['text'].lower()[13:])
  2671. newfile = """"""
  2672. for i in read:
  2673. if name in i:
  2674. pass
  2675. else:
  2676. newfile += i
  2677. n = open(str(chat_id) + '/data/blacklisted.txt', 'w')
  2678. one = str(newfile)
  2679. n.write(one)
  2680. n.close()
  2681.  
  2682. if message.startswith('/blacklist '):
  2683. blacklistedWord = msg['text'].lower()[11:]
  2684. if 'the' == blacklistedWord:
  2685. bot.sendMessage(chat_id, 'That is unreasonable.')
  2686. elif 'this' == blacklistedWord:
  2687. bot.sendMessage(chat_id, 'That is unreasonable.')
  2688. elif 'there' == blacklistedWord:
  2689. bot.sendMessage(chat_id, 'That is unreasonable.')
  2690. elif 'is' == blacklistedWord:
  2691. bot.sendMessage(chat_id, 'That is unreasonable.')
  2692. elif 'that' == blacklistedWord:
  2693. bot.sendMessage(chat_id, 'That is unreasonable.')
  2694. else:
  2695.  
  2696. open(str(chat_id) + "/data/blacklisted.txt", "a").write(str(blacklistedWord) + '\n')
  2697. bot.sendMessage(chat_id, 'Word has been blacklisted. If this word is used, the message will be deleted, and the user will be kicked. /unblacklist to remove words.')
  2698. def banusername():
  2699. with open("data/listofusers.data", 'r') as f:
  2700. lines = f.read().split("\n")
  2701.  
  2702. # print("Number of lines is {}".format(len(lines)))
  2703. if '@' in msg['text'][5:]:
  2704. word = str(msg['text'][5:]).replace('@', "").lower()
  2705. else:
  2706. word = str(msg['text'][5:]).lower()
  2707.  
  2708. # iterate over lines, and print out line numbers which contain
  2709. # the word of interest.
  2710. for i, line in enumerate(lines):
  2711. if word in line.lower(): # or word in line.split() to search for full words
  2712. # print("Word \"{}\" found in line {}".format(word, i + 1))
  2713. foundLine = i
  2714. f = open("data/listofusers.data")
  2715. lines = f.readlines()
  2716. lines[i].split(">:>")[0]
  2717. if os.path.isfile("data/n" + str(lines[i].split(">:>")[0]) + ".txt") == False:
  2718. if os.path.isfile("data/n" + str(lines[i].split(">:>")[0]) + ".txt") == False:
  2719. ownerName = str(msg['from']['first_name'])
  2720. else:
  2721. ownerName = str(open("data/n" + str(msg['from']['id']) + ".txt").read())
  2722.  
  2723. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  2724. bot.sendMessage(chat_id, "I can't ban admins. Sorry!")
  2725. break
  2726. else:
  2727. bot.sendMessage(chat_id, '@' + word + ' has been banned by ' + ownerName)
  2728. bot.kickChatMember(chat_id, int(lines[i].split('>:>')[0]))
  2729. else:
  2730. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  2731. bot.sendMessage(chat_id, "I can't ban admins. Sorry!")
  2732. break
  2733. else:
  2734. usersName = str(open("data/n" + str(lines[i].split(">:>")[0]) + ".txt").read())
  2735. ownerName = str(open("data/n" + str(msg['from']['id']) + ".txt").read())
  2736. bot.sendMessage(chat_id, usersName + ' has been banned.')
  2737. bot.kickChatMember(chat_id, int(lines[i].split('>:>')[0]))
  2738. #with open("data/listofusers.data", 'rw') as file:
  2739. # for line in file:
  2740. # if not line.isspace():
  2741. # file.write(line)
  2742.  
  2743. def kickusername():
  2744. with open("data/listofusers.data", 'r') as f:
  2745. lines = f.read().split("\n")
  2746.  
  2747. # print("Number of lines is {}".format(len(lines)))
  2748. if '@' in msg['text'][6:]:
  2749. word = str(msg['text'][6:]).replace('@', "")
  2750. else:
  2751. word = str(msg['text'][6:])
  2752.  
  2753.  
  2754. for i, line in enumerate(lines):
  2755. if word in line.lower():
  2756. # print("Word \"{}\" found in line {}".format(word, i + 1))
  2757. foundLine = i
  2758. f = open("data/listofusers.data")
  2759. lines = f.readlines()
  2760. lines[i].split(">:>")[0]
  2761. if os.path.isfile("data/n" + str(lines[i].split(">:>")[0]) + ".txt") == False:
  2762. if os.path.isfile("data/n" + str(lines[i].split(">:>")[0]) + ".txt") == False:
  2763. ownerName = str(msg['from']['first_name'])
  2764. else:
  2765. ownerName = str(open("data/n" + str(msg['from']['id']) + ".txt").read())
  2766.  
  2767. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  2768. bot.sendMessage(chat_id, "I can't kick admins. Sorry!")
  2769. break
  2770. else:
  2771. bot.sendMessage(chat_id, '@' + word + ' has been kicked by ' + ownerName)
  2772. bot.kickChatMember(chat_id, int(lines[i].split('>:>')[0]))
  2773. bot.unbanChatMember(chat_id, int(lines[i].split('>:>')[0]))
  2774. else:
  2775. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  2776. bot.sendMessage(chat_id, "I can't kick admins. Sorry!")
  2777. break
  2778. else:
  2779. usersName = str(open("data/n" + str(lines[i].split(">:>")[0]) + ".txt").read())
  2780. if os.path.isfile("data/n" + str(lines[i].split(">:>")[0]) + ".txt") == False:
  2781. ownerName = str(msg['from']['first_name'])
  2782. else:
  2783. ownerName = str(open("data/n" + str(msg['from']['id']) + ".txt").read())
  2784. bot.sendMessage(chat_id, usersName + ' has been kicked by ' + ownerName)
  2785. bot.kickChatMember(chat_id, int(lines[i].split('>:>')[0]))
  2786. bot.unbanChatMember(chat_id, int(lines[i].split('>:>')[0]))
  2787. # with open("data/listofusers.data", 'rw') as file:
  2788. # for line in file:
  2789. # if not line.isspace():
  2790. # file.write(line)
  2791. def unmuteusername():
  2792. with open("data/listofusers.data", 'r') as f:
  2793. lines = f.read().split("\n")
  2794.  
  2795. # print("Number of lines is {}".format(len(lines)))
  2796. if '@' in msg['text'][8:]:
  2797. word = str(msg['text'][8:]).replace('@', "")
  2798. else:
  2799. word = str(msg['text'][8:])
  2800.  
  2801. for i, line in enumerate(lines):
  2802. if word in line.lower():
  2803. foundLine = i
  2804. f = open("data/listofusers.data")
  2805. lines = f.readlines()
  2806. lines[i].split(">:>")[0]
  2807. if os.path.isfile("data/n" + str(lines[i].split(">:>")[0]) + ".txt") == False:
  2808. if os.path.isfile("data/n" + str(lines[i].split(">:>")[0]) + ".txt") == False:
  2809. ownerName = str(msg['from']['first_name'])
  2810. else:
  2811. ownerName = str(open("data/n" + str(msg['from']['id']) + ".txt").read())
  2812.  
  2813. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  2814. try:
  2815.  
  2816. bot.sendMessage(chat_id, '@' + word + ' has been unmuted by ' + ownerName)
  2817. bot.restrictChatMember(chat_id, int(lines[i].split(">:>")[0]),
  2818. can_send_messages=True,
  2819. can_add_web_page_previews=True, can_send_media_messages=True,
  2820. can_send_other_messages=True)
  2821. except:
  2822. bot.sendMessage(chat_id, "I can't unmute admins. Sorry!")
  2823. break
  2824. else:
  2825. bot.sendMessage(chat_id, '@' + word + ' has been unmuted by ' + ownerName)
  2826.  
  2827. bot.restrictChatMember(chat_id, int(lines[i].split(">:>")[0]),
  2828. can_send_messages=True,
  2829. can_add_web_page_previews=True, can_send_media_messages=True,
  2830. can_send_other_messages=True)
  2831. else:
  2832. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  2833. usersName = str(open("data/n" + str(lines[i].split(">:>")[0]) + ".txt").read())
  2834. if os.path.isfile("data/n" + str(lines[i].split(">:>")[0]) + ".txt") == False:
  2835. ownerName = str(msg['from']['first_name'])
  2836. else:
  2837. ownerName = str(open("data/n" + str(msg['from']['id']) + ".txt").read())
  2838. try:
  2839. bot.sendMessage(chat_id, usersName + ' has been unmuted by ' + ownerName)
  2840. bot.restrictChatMember(chat_id, int(lines[i].split(">:>")[0]),
  2841. can_send_messages=True,
  2842. can_add_web_page_previews=True, can_send_media_messages=True,
  2843. can_send_other_messages=True)
  2844. except:
  2845.  
  2846. bot.sendMessage(chat_id, "I can't unmute admins. Sorry!")
  2847. break
  2848. else:
  2849. bot.sendMessage(chat_id, usersName + ' has been unmuted by ' + ownerName)
  2850. bot.restrictChatMember(chat_id, int(lines[i].split(">:>")[0]),
  2851. can_send_messages=True,
  2852. can_add_web_page_previews=True, can_send_media_messages=True,
  2853. can_send_other_messages=True)
  2854. # with open("data/listofusers.data", 'rw') as file:
  2855. # for line in file:
  2856. # if not line.isspace():
  2857. # file.write(line)
  2858.  
  2859.  
  2860.  
  2861.  
  2862. def muteusername():
  2863. with open("data/listofusers.data", 'r') as f:
  2864. lines = f.read().split("\n")
  2865.  
  2866. if '@' in msg['text'][6:]:
  2867. word = str(msg['text'][6:]).replace('@', "")
  2868. else:
  2869. word = str(msg['text'][6:])
  2870.  
  2871. for i, line in enumerate(lines):
  2872. # print("Word \"{}\" found in line {}".format(word, i + 1))
  2873. foundLine = i
  2874. f = open("data/listofusers.data")
  2875. lines = f.readlines()
  2876. lines[i].split(">:>")[0]
  2877. if os.path.isfile("data/n" + str(lines[i].split(">:>")[0]) + ".txt") == False:
  2878. if os.path.isfile("data/n" + str(lines[i].split(">:>")[0]) + ".txt") == False:
  2879. ownerName = str(msg['from']['first_name'])
  2880. else:
  2881. ownerName = str(open("data/n" + str(msg['from']['id']) + ".txt").read())
  2882.  
  2883. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  2884. bot.restrictChatMember(chat_id, int(lines[i].split(">:>")[0]),
  2885. can_send_messages=True,
  2886. can_add_web_page_previews=True, can_send_media_messages=True,
  2887. can_send_other_messages=True)
  2888. bot.sendMessage(chat_id, "I can't mute admins. Sorry!")
  2889. break
  2890. else:
  2891. bot.sendMessage(chat_id, '@' + word + ' has been muted by ' + ownerName)
  2892.  
  2893. bot.restrictChatMember(chat_id, int(lines[i].split(">:>")[0]),
  2894. can_send_messages=False,
  2895. can_add_web_page_previews=False, can_send_media_messages=False,
  2896. can_send_other_messages=False)
  2897. else:
  2898. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  2899. try:
  2900. usersName = str(open("data/n" + str(lines[i].split(">:>")[0]) + ".txt").read())
  2901. if os.path.isfile("data/n" + str(lines[i].split(">:>")[0]) + ".txt") == False:
  2902. ownerName = str(msg['from']['first_name'])
  2903. else:
  2904. ownerName = str(open("data/n" + str(msg['from']['id']) + ".txt").read())
  2905. bot.sendMessage(chat_id, usersName + ' has been unmuted by ' + ownerName)
  2906. bot.restrictChatMember(chat_id, int(lines[i].split(">:>")[0]),
  2907. can_send_messages=True,
  2908. can_add_web_page_previews=True, can_send_media_messages=True,
  2909. can_send_other_messages=True)
  2910. except:
  2911. bot.sendMessage(chat_id, "I can't unmute admins, Sorry!")
  2912. break
  2913.  
  2914. else:
  2915. usersName = str(open("data/n" + str(lines[i].split(">:>")[0]) + ".txt").read())
  2916. if os.path.isfile("data/n" + str(lines[i].split(">:>")[0]) + ".txt") == False:
  2917. ownerName = str(msg['from']['first_name'])
  2918. else:
  2919. ownerName = str(open("data/n" + str(msg['from']['id']) + ".txt").read())
  2920. bot.sendMessage(chat_id, usersName + ' has been muted by ' + ownerName)
  2921. bot.restrictChatMember(chat_id, int(lines[i].split(">:>")[0]),
  2922. can_send_messages=False,
  2923. can_add_web_page_previews=False, can_send_media_messages=False,
  2924. can_send_other_messages=False)
  2925. # with open("data/listofusers.data", 'rw') as file:
  2926. # for line in file:
  2927. # if not line.isspace():
  2928. # file.write(line)
  2929. def nomediausername():
  2930. with open("data/listofusers.data", 'r') as f:
  2931. lines = f.read().split("\n")
  2932.  
  2933. # print("Number of lines is {}".format(len(lines)))
  2934. if '@' in msg['text'][9:]:
  2935. word = str(msg['text'][9:]).replace('@', "")
  2936. else:
  2937. word = str(msg['text'][9:])
  2938.  
  2939. for i, line in enumerate(lines):
  2940. foundLine = i
  2941. f = open("data/listofusers.data")
  2942. lines = f.readlines()
  2943. lines[i].split(">:>")[0]
  2944. if os.path.isfile("data/n" + str(lines[i].split(">:>")[0]) + ".txt") == False:
  2945. if os.path.isfile("data/n" + str(lines[i].split(">:>")[0]) + ".txt") == False:
  2946. ownerName = str(msg['from']['first_name'])
  2947. else:
  2948. ownerName = str(open("data/n" + str(msg['from']['id']) + ".txt").read())
  2949.  
  2950. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  2951. try:
  2952.  
  2953. bot.sendMessage(chat_id, '@' + word + ' has been muted by ' + ownerName)
  2954.  
  2955. bot.restrictChatMember(chat_id, int(lines[i].split(">:>")[0]), can_send_messages=True,
  2956. can_add_web_page_previews=False, can_send_media_messages=False,
  2957. can_send_other_messages=False)
  2958. except:
  2959. bot.sendMessage(chat_id, "I can't mute admins. Sorry!")
  2960. break
  2961. elif str(lines[i].split(">:>")[0]) in open(str(chat_id) + "/data/admin.txt",
  2962. "r").read():
  2963. bot.sendMessage(chat_id, "I can't mute admins. Sorry!")
  2964. break
  2965. else:
  2966. bot.sendMessage(chat_id, '@' + word + ' has been muted by ' + ownerName)
  2967.  
  2968. bot.restrictChatMember(chat_id, int(lines[i].split(">:>")[0]),can_send_messages=True,
  2969. can_add_web_page_previews=False, can_send_media_messages=False,
  2970. can_send_other_messages=False)
  2971. else:
  2972. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  2973. try:
  2974. if os.path.isfile("data/n" + str(lines[i].split(">:>")[0]) + ".txt") == False:
  2975. usersName = str(lines[i].split(">:>")[1])
  2976. else:
  2977. usersName = str(open("data/n" + str(lines[i].split(">:>")[0]) + ".txt").read())
  2978.  
  2979. if os.path.isfile("data/n" + str(msg['from']['id']) + ".txt") == False:
  2980. ownerName = str(msg['from']['first_name'])
  2981. else:
  2982. ownerName = str(open("data/n" + str(msg['from']['id']) + ".txt").read())
  2983. bot.sendMessage(chat_id, usersName + ' has been muted by ' + ownerName)
  2984. bot.restrictChatMember(chat_id, int(lines[i].split(">:>")[0]), can_send_messages=True,
  2985. can_add_web_page_previews=False, can_send_media_messages=False,
  2986. can_send_other_messages=False)
  2987. except:
  2988. bot.sendMessage(chat_id, "I can't mute admins. Sorry!")
  2989. break
  2990. elif str(lines[i].split(">:>")[0]) in open(str(chat_id) + "/data/admin.txt",
  2991. "r").read():
  2992. bot.sendMessage(chat_id, "I can't mute admins. Sorry!")
  2993. break
  2994. else:
  2995. usersName = str(open("data/n" + str(lines[i].split(">:>")[0]) + ".txt").read())
  2996. if os.path.isfile("data/n" + str(lines[i].split(">:>")[0]) + ".txt") == False:
  2997. ownerName = str(msg['from']['first_name'])
  2998. else:
  2999. ownerName = str(open("data/n" + str(msg['from']['id']) + ".txt").read())
  3000. bot.sendMessage(chat_id, usersName + ' has been muted by ' + ownerName)
  3001. bot.restrictChatMember(chat_id, int(lines[i].split(">:>")[0]),can_send_messages=True,
  3002. can_add_web_page_previews=False, can_send_media_messages=False,
  3003. can_send_other_messages=False)
  3004. # with open("data/listofusers.data", 'rw') as file:
  3005. # for line in file:
  3006. # if not line.isspace():
  3007. # file.write(line)
  3008. def unbanusername():
  3009. with open("data/listofusers.data", 'r') as f:
  3010. lines = f.read().split("\n")
  3011.  
  3012. # print("Number of lines is {}".format(len(lines)))
  3013. if '@' in msg['text'][7:]:
  3014. word = str(msg['text'][7:]).replace('@', "")
  3015. else:
  3016. word = str(msg['text'][7:])
  3017.  
  3018. # iterate over lines, and print out line numbers which contain
  3019. # the word of interest.
  3020. for i, line in enumerate(lines):
  3021. if word in line.lower(): # or word in line.split() to search for full words
  3022. # print("Word \"{}\" found in line {}".format(word, i + 1))
  3023. foundLine = i
  3024. f = open("data/listofusers.data")
  3025. lines = f.readlines()
  3026. lines[i].split(">:>")[0]
  3027. if os.path.isfile("data/n" + str(lines[i].split(">:>")[0]) + ".txt") == False:
  3028. if os.path.isfile("data/n" + str(lines[i].split(">:>")[0]) + ".txt") == False:
  3029. ownerName = str(msg['from']['first_name'])
  3030. else:
  3031. ownerName = str(open("data/n" + str(msg['from']['id']) + ".txt").read())
  3032.  
  3033. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  3034. #bot.sendMessage(chat_id, "I can't unban admins. Sorry!")
  3035. break
  3036. elif str(lines[i].split(">:>")[0]) in open(str(chat_id) + "/data/admin.txt",
  3037. "r").read():
  3038. #bot.sendMessage(chat_id, "I can't unban admins. Sorry!")
  3039. break
  3040. else:
  3041. bot.sendMessage(chat_id, '@' + word + ' has been unbanned by ' + ownerName)
  3042. bot.unbanChatMember(chat_id, int(lines[i].split('>:>')[0]))
  3043. else:
  3044. if bot.getChatMember(chat_id, int(lines[i].split(">:>")[0])) in bot.getChatAdministrators(
  3045. chat_id):
  3046. #bot.sendMessage(chat_id, "I can't unban admins. Sorry!")
  3047. break
  3048. elif str(lines[i].split(">:>")[0]) in open(str(chat_id) + "/data/admin.txt",
  3049. "r").read():
  3050. #bot.sendMessage(chat_id, "I can't unban admins. Sorry!")
  3051. break
  3052. else:
  3053. usersName = str(open("data/n" + str(lines[i].split(">:>")[0]) + ".txt").read())
  3054. if os.path.isfile("data/n" + str(lines[i].split(">:>")[0]) + ".txt") == False:
  3055. ownerName = str(msg['from']['first_name'])
  3056. else:
  3057. ownerName = str(open("data/n" + str(msg['from']['id']) + ".txt").read())
  3058. bot.sendMessage(chat_id, usersName + ' has been unbanned by ' + ownerName)
  3059. bot.unbanChatMember(chat_id, int(lines[i].split('>:>')[0]))
  3060. # with open("data/listofusers.data", 'rw') as file:
  3061. # for line in file:
  3062. # if not line.isspace():
  3063. # file.write(line)
  3064. if "/ban " in message:
  3065. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  3066. if 'reply_to_message' in msg:
  3067. if msg['reply_to_message']['from']['id'] != messageFromID:
  3068. if "-" in message[5:]:
  3069. bot.sendMessage(chat_id, "lol nice try")
  3070. else:
  3071. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  3072. bot.sendMessage(chat_id, "I can't ban admins. Sorry!")
  3073. elif str(msg['reply_to_message']['from']['id']) in open(str(chat_id) + "/data/admin.txt", "r").read():
  3074. bot.sendMessage(chat_id, "I can't ban admins. Sorry!")
  3075. else:
  3076. if re.search('[a-zA-Z]', message[5:]):
  3077. bot.kickChatMember(chat_id, msg['reply_to_message']['from']['id'])
  3078. bot.sendMessage(chat_id,
  3079. msg['reply_to_message']['from']['first_name'] + " has been banned by " +
  3080. msg['from']['first_name'] + ".")
  3081. else:
  3082. if int(str(message[5:])) > 10081:
  3083. bot.sendMessage(chat_id, "Cannot ban a person for more than a week.")
  3084. else:
  3085. t = threading.Thread(target=bantimer)
  3086. t.start()
  3087. open(str(chat_id) + "/data/bantimer" + str(msg['reply_to_message']['from']['id']) + ".txt", "w").write(
  3088. str(message[5:]))
  3089. bot.sendMessage(chat_id, usersName + " has been banned for " + str(message[5:]) + " minute(s).", reply_to_message_id=msg['message_id'])
  3090. bot.kickChatMember(chat_id, msg['reply_to_message']['from']['id'])
  3091. else:
  3092. if re.search('[a-zA-Z]', message[5:]):
  3093. if '@' in str(msg['text'][5:]):
  3094. t = threading.Thread(target=banusername)
  3095. t.start()
  3096. else:
  3097. ()
  3098. if message == '/ban':
  3099. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  3100. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  3101. bot.sendMessage(chat_id, "I can't ban admins. Sorry!")
  3102. else:
  3103. if str(msg['reply_to_message']['from']['id']) in open(str(chat_id) + "/data/admin.txt", "r").read():
  3104. bot.sendMessage(chat_id, "I can't ban admins. Sorry!")
  3105. else:
  3106. bot.sendMessage(chat_id, msg['reply_to_message']['from']['first_name'] + " has been banned by " +
  3107. msg['from']['first_name'] + ".")
  3108. open(str(chat_id) + "/data/unban.txt", "w").write(
  3109. str(msg['reply_to_message']['from']['id']))
  3110. global banned
  3111. bot.kickChatMember(chat_id, msg['reply_to_message']['from']['id'])
  3112. else:
  3113. ()
  3114. if message == '/mute':
  3115. if 'reply_to_message' in msg:
  3116. bot.restrictChatMember(chat_id, msg['reply_to_message']['from']['id'], can_send_messages=False,
  3117. can_add_web_page_previews=False, can_send_media_messages=False,
  3118. can_send_other_messages=False)
  3119. bot.sendMessage(chat_id, usersName + " has been muted.", reply_to_message_id=msg['message_id'])
  3120. else:
  3121. if '@' in msg['text']:
  3122. t = threading.Thread(target=muteusername)
  3123. t.start()
  3124. def mutetimer():
  3125. timer = int(str(open(str(chat_id) + "/data/mutetimer" + str(msg['reply_to_message']['from']['id']) + ".txt", "r").read())) * 60
  3126. time.sleep(timer)
  3127. bot.restrictChatMember(chat_id, msg['reply_to_message']['from']['id'], can_send_messages=True,
  3128. can_add_web_page_previews=True, can_send_media_messages=True,
  3129. can_send_other_messages=True)
  3130. bot.sendMessage(chat_id, usersName + " has been unmuted.", reply_to_message_id=msg['message_id'])
  3131. if "/mute " in message:
  3132. if 'reply_to_message' in msg:
  3133. if msg['reply_to_message']['from']['id'] != messageFromID:
  3134. if "-" in message[6:]:
  3135. bot.sendMessage(chat_id, "lol nice try")
  3136. else:
  3137. if re.search('[a-zA-Z]', message[6:]):
  3138. bot.restrictChatMember(chat_id, msg['reply_to_message']['from']['id'], can_send_messages=False,
  3139. can_add_web_page_previews=False, can_send_media_messages=False,
  3140. can_send_other_messages=False)
  3141. bot.sendMessage(chat_id, usersName + " has been muted.", reply_to_message_id=msg['message_id'])
  3142. else:
  3143. if int(str(message[6:])) > 10081:
  3144. bot.sendMessage(chat_id, "Cannot mute a person for more than a week.")
  3145. else:
  3146. t = threading.Thread(target=mutetimer)
  3147. t.start()
  3148. open(str(chat_id) + "/data/mutetimer" + str(msg['reply_to_message']['from']['id']) + ".txt", "w").write(
  3149. str(message[6:]))
  3150. bot.restrictChatMember(chat_id, msg['reply_to_message']['from']['id'],
  3151. can_send_messages=False,
  3152. can_add_web_page_previews=False, can_send_media_messages=False,
  3153. can_send_other_messages=False)
  3154. bot.sendMessage(chat_id, usersName + " has been muted for " + str(message[6:]) + " minute(s).", reply_to_message_id=msg['message_id'])
  3155. else:
  3156. if '@' in msg['text']:
  3157. t = threading.Thread(target=muteusername)
  3158. t.start()
  3159. if "/unmute" in message:
  3160. if 'reply_to_message' in msg:
  3161. bot.restrictChatMember(chat_id, msg['reply_to_message']['from']['id'], can_send_messages=True,
  3162. can_add_web_page_previews=True, can_send_media_messages=True,
  3163. can_send_other_messages=True)
  3164. bot.sendMessage(chat_id, usersName + " has been unmuted.", reply_to_message_id=msg['message_id'])
  3165. else:
  3166. if '@' in msg['text']:
  3167. t = threading.Thread(target=unmuteusername)
  3168. t.start()
  3169. if "/nomedia" in message:
  3170. if 'reply_to_message' in msg:
  3171. bot.restrictChatMember(chat_id, msg['reply_to_message']['from']['id'], can_send_messages=True,
  3172. can_add_web_page_previews=False, can_send_media_messages=False,
  3173. can_send_other_messages=False)
  3174. bot.sendMessage(chat_id, usersName + " has restricted media.", reply_to_message_id=msg['message_id'])
  3175. else:
  3176. if '@' in msg['text']:
  3177. t = threading.Thread(target=nomediausername)
  3178. t.start()
  3179. if "/unrestrict" in message:
  3180. bot.restrictChatMember(chat_id, msg['reply_to_message']['from']['id'], can_send_messages=True,
  3181. can_add_web_page_previews=True, can_send_media_messages=True,
  3182. can_send_other_messages=True)
  3183. bot.sendMessage(chat_id, usersName + " has been unrestricted.", reply_to_message_id=msg['message_id'])
  3184. if "/unban" in message:
  3185. if str(botID) in str(unique_lines.keys()):
  3186. if 'reply_to_message' in msg:
  3187. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  3188. bot.sendMessage(chat_id, "I can't unban admins. Sorry!")
  3189. else:
  3190. bot.sendMessage(chat_id, "User has been unbanned")
  3191. open(str(chat_id) + "/data/unban.txt", "w").write(
  3192. str(msg['reply_to_message']['from']['id']))
  3193. global banned
  3194. bot.unbanChatMember(chat_id, msg['reply_to_message']['from']['id'])
  3195. else:
  3196. ()
  3197. #if '@' in msg['text']:
  3198. # t = threading.Thread(target=unbanusername)
  3199. # t.start()
  3200. else:
  3201. bot.sendMessage(chat_id, "Error: I need to be admin.")
  3202. if "/unban " in message:
  3203. if str(botID) in str(unique_lines.keys()):
  3204. if 'reply_to_message' in msg:
  3205. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  3206. bot.sendMessage(chat_id, "I can't unban admins. Sorry!")
  3207. else:
  3208. bot.sendMessage(chat_id, "User has been unbanned")
  3209. open(str(chat_id) + "/data/unban.txt", "w").write(
  3210. str(msg['reply_to_message']['from']['id']))
  3211. global banned
  3212. bot.unbanChatMember(chat_id, msg['reply_to_message']['from']['id'])
  3213. elif '@' in msg['text']:
  3214. t = threading.Thread(target=unbanusername)
  3215. t.start()
  3216. else:
  3217. bot.sendMessage(chat_id, "Error: I need to be admin.")
  3218. if "/kick" in message:
  3219. if str(botID) in str(unique_lines.keys()):
  3220. if 'reply_to_message' in msg:
  3221. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  3222. bot.sendMessage(chat_id, "I can't kick admins. Sorry!")
  3223. else:
  3224. if str(msg['reply_to_message']['from']['id']) in open(str(chat_id) + "/data/admin.txt", "r").read():
  3225. bot.sendMessage(chat_id, "I can't kick admins. Sorry!")
  3226. else:
  3227. bot.sendMessage(chat_id,
  3228. msg['reply_to_message']['from']['first_name'] + " has been kicked by " +
  3229. msg['from'][
  3230. 'first_name'] + ".")
  3231. bot.kickChatMember(chat_id, msg['reply_to_message']['from']['id'])
  3232. bot.unbanChatMember(chat_id, msg['reply_to_message']['from']['id'])
  3233. elif '@' in msg['text']:
  3234. t = threading.Thread(target=kickusername)
  3235. t.start()
  3236. if isPrivateMessage == False:
  3237. if message.startswith("/title"):
  3238. try:
  3239. bot.setChatTitle(chat_id, str(msg['text'][7:]))
  3240. except:
  3241. bot.sendMessage(chat_id, "An error has occurred")
  3242. if "/byebot" in message:
  3243. bot.sendMessage(chat_id, "Bye! If you had any issues, contact @spoon. Thanks!")
  3244. bot.leaveChat(chat_id)
  3245. else:
  3246. bot.sendMessage(chat_id, "Sorry.. I will leave you alone :( PM whenever")
  3247. if isPrivateMessage == False:
  3248. if "/warn" in message:
  3249. if str(botID) in str(unique_lines.keys()):
  3250. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  3251. bot.sendMessage(chat_id, "Admins can not get warned.")
  3252. else:
  3253. if os.path.isfile(str(chat_id) + "/data/" + str(
  3254. msg['reply_to_message']['from']['id']) + ".txt") == False:
  3255. filet = open(str(chat_id) + "/data/" + str(msg['reply_to_message']['from']['id']) + ".txt", "w")
  3256. filew = open(str(chat_id) + "/data/" + str(msg['reply_to_message']['from']['id']) + ".txt")
  3257. filer = open(str(chat_id) + "/data/" + str(msg['reply_to_message']['from']['id']) + ".txt", "r")
  3258. filee = open(str(chat_id) + "/data/" + str(msg['reply_to_message']['from']['id']) + ".txt", "r+")
  3259. filet.write("1")
  3260. bot.sendMessage(chat_id, usersName + " has been warned by " + str(msg['from']['first_name']) + " *(1/3)*", parse_mode="markdown")
  3261.  
  3262. open("data/temp.txt", "w").write(str(msg['reply_to_message']['from']['id']))
  3263. global warnd
  3264. else:
  3265. if "1" in open(str(chat_id) + "/data/" + str(msg['reply_to_message']['from']['id']) + ".txt", "r"):
  3266. open(str(chat_id) + "/data/" + str(msg['reply_to_message']['from']['id']) + ".txt", "w").write(
  3267. "2")
  3268. bot.sendMessage(chat_id, usersName + "has been warned by " + str(
  3269. msg['from']['first_name']) + " *(2/3)*", parse_mode="markdown")
  3270.  
  3271. open(str(chat_id) + "/data/temp.txt", "w").write(str(msg['reply_to_message']['from']['id']))
  3272. elif "2" in open(str(chat_id) + "/data/" + str(msg['reply_to_message']['from']['id']) + ".txt",
  3273. "r"):
  3274. open(str(chat_id) + "/data/" + str(msg['reply_to_message']['from']['id']) + ".txt", "w").write(
  3275. "3")
  3276. bot.sendMessage(chat_id, "You exceeded warn limit, you are now banned. *(3/3)*",
  3277. parse_mode="markdown")
  3278. bot.kickChatMember(chat_id, msg['reply_to_message']['from']['id'])
  3279. os.remove(str(chat_id) + "/data/" + str(msg['reply_to_message']['from']['id']) + ".txt")
  3280. open(str(chat_id) + "/data/temp.txt", "w").write(str(msg['reply_to_message']['from']['id']))
  3281. if "/photo" in message:
  3282. if 'http' in message:
  3283. pass
  3284. else:
  3285. if "True" in open(str(chat_id) + "/data/photo.txt", "r"):
  3286. open(str(chat_id) + "/data/photo.txt", "w").write("False")
  3287. bot.sendMessage(chat_id, "I will no longer edit photos")
  3288. else:
  3289. open(str(chat_id) + "/data/photo.txt", "w").write("True")
  3290. bot.sendMessage(chat_id, "I will now edit photos")
  3291. if "/wel " in message:
  3292. if "Photo" in open(str(chat_id) + "/data/greet.txt", "r"):
  3293. if len(msg['text'][5:]) > 15:
  3294. bot.sendMessage(chat_id, "This message is too long for a picture message, please try again. Or switch to text by typing /greet")
  3295. else:
  3296. open(str(chat_id) + "/data/greettext.txt", "w").write(msg['text'][5:])
  3297. bot.sendMessage(chat_id, "Welcome message set!")
  3298. else:
  3299. if "True" in open(str(chat_id) + "/wel.txt").read():
  3300. open(str(chat_id) + "/welcome.txt", "w").write(msg['text'][5:])
  3301. bot.sendMessage(chat_id, "Welcome message set!")
  3302. else:
  3303. bot.sendMessage(chat_id, "Welcome messages have been disabled. To re-enable them, type /wt")
  3304. if "/pin" in message:
  3305. if 'reply_to_message' in msg:
  3306. bot.pinChatMessage(chat_id, msg['reply_to_message']['message_id'],
  3307. disable_notification=True)
  3308. telegram.Bot.deleteMessage(self=Bot, chat_id=chat_id, message_id=messageID)
  3309. else:
  3310. bot.sendMessage(chat_id, "Reply to message.")
  3311. if "/wt" in message:
  3312. if "True" in open(str(chat_id) + "/wel.txt", "r"):
  3313. open(str(chat_id) + "/wel.txt", "w").write("False")
  3314. bot.sendMessage(chat_id, "Welcome messages have been disabled.")
  3315. else:
  3316. open(str(chat_id) + "/wel.txt", "w").write("True")
  3317. bot.sendMessage(chat_id, "Welcome messages have been enabled.")
  3318. if "/gt" in message:
  3319. if "True" in open(str(chat_id) + "/data/games.txt", "r"):
  3320. open(str(chat_id) + "/data/games.txt", "w").write("False")
  3321. bot.sendMessage(chat_id, "Games have been disabled.")
  3322. else:
  3323. open(str(chat_id) + "/data/games.txt", "w").write("True")
  3324. bot.sendMessage(chat_id, "Games have been enabled.")
  3325. if "/rt" in message:
  3326. if "True" in open(str(chat_id) + "/data/roll.txt", "r"):
  3327. open(str(chat_id) + "/data/roll.txt", "w").write("False")
  3328. bot.sendMessage(chat_id, "I will no longer roll dice.")
  3329. else:
  3330. open(str(chat_id) + "/data/roll.txt", "w").write("True")
  3331. bot.sendMessage(chat_id, "I will now roll dice.")
  3332. if "/link" in message:
  3333. if "True" in open(str(chat_id) + "/data/link.txt", "r"):
  3334. open(str(chat_id) + "/data/link.txt", "w").write("False")
  3335. bot.sendMessage(chat_id, "I will no longer remove invite links.")
  3336. else:
  3337. open(str(chat_id) + "/data/link.txt", "w").write("True")
  3338. bot.sendMessage(chat_id, "I will now remove invite links.")
  3339. if "/jt" in message:
  3340. if "True" in open(str(chat_id) + "/data/jokes.txt", "r"):
  3341. open(str(chat_id) + "/data/jokes.txt", "w").write("False")
  3342. bot.sendMessage(chat_id, "I will no longer tell jokes.")
  3343. else:
  3344. open(str(chat_id) + "/data/jokes.txt", "w").write("True")
  3345. bot.sendMessage(chat_id, "I will now tell jokes.")
  3346. if "/eb" in message:
  3347. if "True" in open(str(chat_id) + "/data/8ball.txt", "r"):
  3348. open(str(chat_id) + "/data/8ball.txt", "w").write("False")
  3349. bot.sendMessage(chat_id, "I will no longer answer questions.")
  3350. else:
  3351. open(str(chat_id) + "/data/8ball.txt", "w").write("True")
  3352. bot.sendMessage(chat_id, "I will now answer questions.")
  3353. if "/spam" in message:
  3354. if "True" in open(str(chat_id) + "/data/spam.txt", "r"):
  3355. open(str(chat_id) + "/data/spam.txt", "w").write("False")
  3356. bot.sendMessage(chat_id, "I will no longer restrict spamming.")
  3357. else:
  3358. open(str(chat_id) + "/data/spam.txt", "w").write("True")
  3359. bot.sendMessage(chat_id, "I will now restrict spamming.")
  3360. if "/setpref " in message:
  3361. open(str(chat_id) + "/data/compref.txt", "w").write(str(msg['text'])[9:])
  3362. bot.sendMessage(chat_id, "I will now respond to '" + str(open(str(chat_id)) + '/data/compref.txt', 'r').read() + "' (" + str(open(str(chat_id + '/data/compref.txt, 'r''))) + 'kick)')
  3363. if "/voice" in message:
  3364. if "True" in open(str(chat_id) + "/data/tts.txt", "r"):
  3365. open(str(chat_id) + "/data/tts.txt", "w").write("False")
  3366. bot.sendMessage(chat_id, "I will no longer speak words.")
  3367. else:
  3368. open(str(chat_id) + "/data/tts.txt", "w").write("True")
  3369. bot.sendMessage(chat_id, "I will now speak words.")
  3370. if "/urbandict" in message:
  3371. if "True" in open(str(chat_id) + "/data/urban.txt", "r"):
  3372. open(str(chat_id) + "/data/urban.txt", "w").write("False")
  3373. bot.sendMessage(chat_id, "I will now define words from UD.")
  3374. else:
  3375. open(str(chat_id) + "/data/urban.txt", "w").write("True")
  3376. bot.sendMessage(chat_id, "I will no longer define words from UD.")
  3377. if "/lb" in message:
  3378. if "True" in open(str(chat_id) + "/data/leaderboard.txt", "r"):
  3379. open(str(chat_id) + "/data/leaderboard.txt", "w").write("False")
  3380. bot.sendMessage(chat_id, "I will no longer display the leaderboard.")
  3381. else:
  3382. open(str(chat_id) + "/data/leaderboard.txt", "w").write("True")
  3383. bot.sendMessage(chat_id, "I will now display the leaderboard.")
  3384. if "/arabic" in message:
  3385. if "True" in open(str(chat_id) + "/data/arabic.txt", "r"):
  3386. open(str(chat_id) + "/data/arabic.txt", "w").write("False")
  3387. bot.sendMessage(chat_id, "I will no longer restrict arabic.")
  3388. else:
  3389. open(str(chat_id) + "/data/arabic.txt", "w").write("True")
  3390. bot.sendMessage(chat_id, "I will now restrict arabic.")
  3391. if "/lock" in message:
  3392. if "True" in open(str(chat_id) + "/data/lock.txt", "r"):
  3393. open(str(chat_id) + "/data/lock.txt", "w").write("False")
  3394. bot.sendMessage(chat_id, "The group is no longer locked.")
  3395. else:
  3396. open(str(chat_id) + "/data/lock.txt", "w").write("True")
  3397. bot.sendMessage(chat_id, "The group is now locked, no one can join")
  3398. if "/antibot" in message:
  3399. if "True" in open(str(chat_id) + "/data/antibot.txt", "r"):
  3400. open(str(chat_id) + "/data/antibot.txt", "w").write("False")
  3401. bot.sendMessage(chat_id, "I will no longer kick bots.")
  3402. else:
  3403. open(str(chat_id) + "/data/antibot.txt", "w").write("True")
  3404. bot.sendMessage(chat_id, "I will now kick bots.")
  3405. if "/greet" in message:
  3406. if "Text" in open(str(chat_id) + "/data/greet.txt", "r"):
  3407. open(str(chat_id) + "/data/greet.txt", "w").write("Photo")
  3408. bot.sendMessage(chat_id, "I will now greet with photo.")
  3409. else:
  3410. open(str(chat_id) + "/data/greet.txt", "w").write("Text")
  3411. bot.sendMessage(chat_id, "I will now greet with text.")
  3412. if message == "/wel":
  3413. if "True" in open(str(chat_id) + "/wel.txt").read():
  3414. bot.sendMessage(chat_id,"To set a message, type '/wel Welcome message.'\n$u = Username\n$n = User's name\n$t = Title")
  3415. else:
  3416. bot.sendMessage(chat_id, "Welcome messages have been disabled. To re-enable them, type /wt")
  3417. if "/reset" in message:
  3418. if str(botID) in str(unique_lines.keys()):
  3419. if os.path.isfile(str(chat_id) + "/data/" + str(
  3420. msg['reply_to_message']['from']['id']) + ".txt") == True:
  3421. os.remove(str(chat_id) + "/data/" + str(msg['reply_to_message']['from']['id']) + ".txt")
  3422. bot.sendMessage(chat_id, "Poof! All warns have been removed.")
  3423. else:
  3424. bot.sendMessage(chat_id, usersName + " has no warns.")
  3425. if "/toggles" in message:
  3426. t = threading.Thread(target=toggle)
  3427. t.start()
  3428. if "/give " in message:
  3429. if 'username' in msg['from']:
  3430. sender = "\n\u251c@" + str(msg['from']['username'])
  3431. else:
  3432. sender = ""
  3433. if 'username' in msg['reply_to_message']['from']:
  3434. receiver = "\n\u251c@" + str(msg['reply_to_message']['from']['username'])
  3435. else:
  3436. receiver = ""
  3437. if "reply_to_message" in msg:
  3438. if msg['reply_to_message']['from']['id'] != messageFromID:
  3439. if "-" in message[6:]:
  3440. bot.sendMessage(chat_id, "lol nice try")
  3441. bot.sendMessage(374986841, "\U0001F3E6**Bank**\U0001F3E6\n\u250cSender \U0001F4E4\n\u251c" + str(
  3442. msg['from']['first_name']) + sender + "\n\u251c" + str(
  3443. open("rooms/" + str(msg['from']['id']) + "money.txt",
  3444. "r").read()) + " coins\n\u251cSent " + str(msg['text'][6:]) + "\n\u2514" + str(
  3445. msg['from']['id']) + "\n\n\u250cReceiver \U0001F4E5\n\u251c" + str(
  3446. msg['reply_to_message']['from']['first_name']) + receiver + "\n\u251c" + str(
  3447. open("rooms/" + str(msg['reply_to_message']['from']['id']) + "money.txt",
  3448. "r").read()) + " coins\n\u2514" + str(msg['reply_to_message']['from'][
  3449. 'id']) + "\n\n\u250cReceipt \U0001F4C3\n\u2514Success? \U0001F534",
  3450. parse_mode="markdown", disable_notification=True)
  3451. else:
  3452. if re.search('[a-zA-Z]', message[6:]):
  3453. print(
  3454. str(open("rooms/" + str(messageFromID) + "money.txt", "r").readlines()).replace("[",
  3455. "").replace(
  3456. "'", "").replace("]", ""))
  3457. bot.sendMessage(374986841,
  3458. "\U0001F3E6**Bank**\U0001F3E6\n\u250cSender \U0001F4E4\n\u251c" + str(
  3459. msg['from']['first_name']) + sender + "\n\u251c" + str(
  3460. open("rooms/" + str(msg['from']['id']) + "money.txt",
  3461. "r").read()) + "\n\u2514" + str(
  3462. msg['from']['id']) + "\n\n\u250cReceiver \U0001F4E5\n\u251c" + str(
  3463. msg['reply_to_message']['from'][
  3464. 'first_name']) + receiver + "\n\u251c" + str(
  3465. open("rooms/" + str(msg['reply_to_message']['from']['id']) + "money.txt",
  3466. "r").read()) + " coins\n\u2514" + str(msg['reply_to_message']['from'][
  3467. 'id']) + "\n\n\u250cReceipt \U0001F4C3\n\u251cSent " + str(
  3468. msg['text'][6:]) + "\n\u2514Success? \U0001F534",
  3469. parse_mode="markdown")
  3470. else:
  3471. if int(str(open("rooms/" + str(messageFromID) + "money.txt", "r").readlines()).replace(
  3472. "[",
  3473. "").replace(
  3474. "'", "").replace("]", "")) == int(str(msg['text'][6:])):
  3475. minus = int(
  3476. str(open("rooms/" + str(messageFromID) + "money.txt", "r").readlines()).replace(
  3477. "[",
  3478. "").replace(
  3479. "'", "").replace("]", "")) - int(str(msg['text'][6:]))
  3480. add = int(
  3481. str(open("rooms/" + str(msg['reply_to_message']['from']['id']) + "money.txt",
  3482. "r").readlines()).replace("[", "").replace(
  3483. "'", "").replace("]", "")) + int(message[6:])
  3484. open("rooms/" + str(messageFromID) + "money.txt", "w").write("0")
  3485. open("rooms/" + str(msg['reply_to_message']['from']['id']) + "money.txt",
  3486. "w").write(
  3487. str(add))
  3488. bot.sendMessage(chat_id, "Sent *" + str(msg['text'][6:]) + "* coins!",
  3489. parse_mode="markdown")
  3490. bot.sendMessage(374986841,
  3491. "\U0001F3E6**Bank**\U0001F3E6\n\u250cSender \U0001F4E4\n\u251c" + str(
  3492. msg['from']['first_name']) + sender + "\n\u251c" + str(
  3493. open("rooms/" + str(msg['from']['id']) + "money.txt",
  3494. "r").read()) + "\n\u2514" + str(
  3495. msg['from']['id']) + "\n\n\u250cReceiver \U0001F4E5\n\u251c" + str(
  3496. msg['reply_to_message']['from'][
  3497. 'first_name']) + receiver + "\n\u251c" + str(open(
  3498. "rooms/" + str(msg['reply_to_message']['from']['id']) + "money.txt",
  3499. "r").read()) + " coins\n\u2514" + str(msg['reply_to_message']['from'][
  3500. 'id']) + "\n\n\u250cReceipt \U0001F4C3\n\u251cSent " + str(
  3501. msg['text'][6:]) + "\n\u2514Success? \U0001F535",
  3502. parse_mode="markdown")
  3503. elif int(str(open("rooms/" + str(messageFromID) + "money.txt", "r").readlines()).replace(
  3504. "[",
  3505. "").replace(
  3506. "'", "").replace("]", "")) > int(str(msg['text'][6:])):
  3507. minus = int(
  3508. str(open("rooms/" + str(messageFromID) + "money.txt", "r").readlines()).replace(
  3509. "[",
  3510. "").replace(
  3511. "'", "").replace("]", "")) - int(str(msg['text'][6:]))
  3512. add = int(
  3513. str(open("rooms/" + str(msg['reply_to_message']['from']['id']) + "money.txt",
  3514. "r").readlines()).replace("[", "").replace(
  3515. "'", "").replace("]", "")) + int(message[6:])
  3516. open("rooms/" + str(messageFromID) + "money.txt", "w").write(str(minus))
  3517. open("rooms/" + str(msg['reply_to_message']['from']['id']) + "money.txt",
  3518. "w").write(
  3519. str(add))
  3520. bot.sendMessage(chat_id, "Sent *" + str(msg['text'][6:]) + "* coins!",
  3521. parse_mode="markdown")
  3522. bot.sendMessage(374986841,
  3523. "\U0001F3E6**Bank**\U0001F3E6\n\u250cSender \U0001F4E4\n\u251c" + str(
  3524. msg['from']['first_name']) + sender + "\n\u251c" + str(
  3525. open("rooms/" + str(msg['from']['id']) + "money.txt",
  3526. "r").read()) + "\n\u2514" + str(
  3527. msg['from']['id']) + "\n\n\u250cReceiver \U0001F4E5\n\u251c" + str(
  3528. msg['reply_to_message']['from'][
  3529. 'first_name']) + receiver + "\n\u251c" + str(open(
  3530. "rooms/" + str(msg['reply_to_message']['from']['id']) + "money.txt",
  3531. "r").read()) + " coins\n\u2514" + str(msg['reply_to_message']['from'][
  3532. 'id']) + "\n\n\u250cReceipt \U0001F4C3\n\u251cSent " + str(
  3533. msg['text'][6:]) + "\n\u2514Success? \U0001F535",
  3534. parse_mode="markdown")
  3535. else:
  3536. bot.sendMessage(chat_id, "You don't have enough money.")
  3537. bot.sendMessage(374986841,
  3538. "\U0001F3E6**Bank**\U0001F3E6\n\u250cSender \U0001F4E4\n\u251c" + str(
  3539. msg['from']['first_name']) + sender + "\n\u251c" + str(
  3540. open("rooms/" + str(msg['from']['id']) + "money.txt",
  3541. "r").read()) + "\n\u2514" + str(
  3542. msg['from']['id']) + "\n\n\u250cReceiver \U0001F4E5\n\u251c" + str(
  3543. msg['reply_to_message']['from'][
  3544. 'first_name']) + receiver + "\n\u251c" + str(open(
  3545. "rooms/" + str(msg['reply_to_message']['from']['id']) + "money.txt",
  3546. "r").read()) + " coins\n\u2514" + str(msg['reply_to_message']['from'][
  3547. 'id']) + "\n\n\u250cReceipt \U0001F4C3\n\u251cSent " + str(
  3548. msg['text'][6:]) + "\n\u2514Success? \U0001F534",
  3549. parse_mode="markdown")
  3550. else:
  3551. bot.sendMessage(chat_id, "lol nice try")
  3552. if "/jokes" in message:
  3553. if "True" in open(str(chat_id) + "/data/jokes.txt", "r"):
  3554. bot.sendMessage(chat_id, random.choice(jokes))
  3555.  
  3556. def place_value(number):
  3557. return ("{:,}".format(number))
  3558.  
  3559. def totalcoins():
  3560. dir = '/home/*spoon/rooms/*money.txt'
  3561. #dir = '/home/*spoon/Desktop/Coding/rooms/*money.txt'
  3562. cv_img = []
  3563.  
  3564. open('texting.txt', 'w').write('')
  3565. open('data/totalcoins.txt', 'w').write('0')
  3566. for img in glob.glob(dir):
  3567. try:
  3568. n = open(img, 'r').read()
  3569. if os.path.isfile('data/totalcoins.txt') == False:
  3570. open('data/totalcoins.txt', 'w').write(str(n))
  3571. else:
  3572. open('texting.txt', 'a+').write(n + ',')
  3573. original = open('data/totalcoins.txt', 'r').readlines()
  3574. minus = int(
  3575. str(original).replace("[", "").replace("'", "").replace("]", "")) + int(str(n))
  3576. open('data/totalcoins.txt',
  3577. "w").write(
  3578. str(minus))
  3579. print(open('data/totalcoins.txt', 'r').read())
  3580. cv_img.append(n)
  3581. print(open('data/totalcoins.txt', 'r').read())
  3582. except:
  3583. pass
  3584. bot.sendMessage(chat_id, 'There are a total of ' + place_value(int(str(open('data/totalcoins.txt', 'r').read()))) + ' coins.')
  3585.  
  3586. def totalmessage():
  3587. cv_img = []
  3588. open('data/totalmessages' + str(msg['from']['id']) + '.txt', 'w').write('0')
  3589. for img in glob.glob('/home/*spoon/*/messages/' + str(msg['from']['id']) + '.txt'):
  3590. n = open(img, 'r').read()
  3591. if os.path.isfile('data/totalmessages' + str(msg['from']['id']) + '.txt') == False:
  3592. open('data/totalmessages' + str(msg['from']['id']) + '.txt', 'w').write(str(n))
  3593. else:
  3594. original = open('data/totalmessages' + str(msg['from']['id']) + '.txt', 'r').readlines()
  3595. minus = int(
  3596. str(original).replace("[", "").replace("'", "").replace("]", "")) + int(str(n))
  3597. open('data/totalmessages' + str(msg['from']['id']) + '.txt',
  3598. "w").write(
  3599. str(minus))
  3600. print(open('data/totalmessages' + str(msg['from']['id']) + '.txt', 'r').read())
  3601. cv_img.append(n)
  3602. print(open('data/totalmessages' + str(msg['from']['id']) + '.txt', 'r').read())
  3603. bot.sendMessage(chat_id, 'You have sent a total of ' + place_value(int(str(open('data/totalmessages' + str(msg['from']['id']) + '.txt', 'r').read()))) + ' messages in all of the groups we share.')
  3604. if '/totalmessages' in message:
  3605. t = threading.Thread(target=totalmessage)
  3606. t.start()
  3607. if '/countcoin' in message:
  3608. t = threading.Thread(target=totalcoins)
  3609. t.start()
  3610. def testing():
  3611. Bot.send_chat_action(chat_id, action=telegram.ChatAction.TYPING)
  3612. #font_file = 'NotoColorEmoji.ttf'
  3613. #symbola_font = TTFont('Symbola', font_file)
  3614. #pdfmetrics.registerFont(symbola_font)
  3615. try:
  3616. color = 'black'
  3617. color1 = 'white'
  3618. profiles = bot.getUserProfilePhotos(msg['from']['id'])
  3619. file_id = profiles['photos'][0][-1]['file_id']
  3620. filename = str(msg['from']['id']) + ".jpg"
  3621. bot.download_file(file_id, filename)
  3622. im = Image.open(filename)
  3623. img = PIL.Image.new("RGB", (640, 800), (color))
  3624. draw = PIL.ImageDraw.Draw(img)
  3625. font = ImageFont.truetype("comic.ttf", int("65"))
  3626. except:
  3627. filename = "NoPFP.jpg"
  3628. im = Image.open(filename)
  3629. img = Image.new("RGB", (640, 800), (color))
  3630. draw = PIL.ImageDraw.Draw(img)
  3631. font = ImageFont.truetype("comic.ttf", int("65"))
  3632. if os.path.isfile("data/n" + str(msg['from']['id']) + ".txt") == False:
  3633. if len(msg['from']['first_name']) > 15:
  3634. line2 = msg['from']['first_name'][:15] + "...!"
  3635. else:
  3636. line2 = msg['from']['first_name'] + "!"
  3637. else:
  3638. if len(open("data/n" + str(msg['from']['id']) + ".txt").read()) > 15:
  3639. line2 = open("data/n" + str(msg['from']['id']) + ".txt").read()[:15] + "...!"
  3640. else:
  3641. line2 = open("data/n" + str(msg['from']['id']) + ".txt").read() + "!"
  3642. line1 = 'Welcome'
  3643. w, h = font.getsize(line1)
  3644. w2, h2 = font.getsize(line2)
  3645. draw.text(((650 - w) / 2, (1360 - h) / 2), line1, font=font, fill=str(color1))
  3646. draw.text(((650 - w2) / 2, ((1300 - h2) / 2) + 100), line2, font=font, fill=str(color1))
  3647. img.paste(im, (0, 0))
  3648. img.save("1" + filename)
  3649. bot.sendPhoto(chat_id, open("1" + filename, "rb"))
  3650. os.remove("1" + filename)
  3651. if filename != "NoPFP.jpg":
  3652. os.remove(filename)
  3653. if '/megatest' in message:
  3654. t = threading.Thread(target=testing)
  3655. t.start()
  3656.  
  3657.  
  3658.  
  3659. def define():
  3660. if "False" in open(str(chat_id) + "/data/urban.txt", "r"):
  3661. heart = u'\u2764'
  3662. term = msg['text'][4:].lower()
  3663. if term == "spoon":
  3664. bot.sendMessage(chat_id, "The creator of this bot @spoon" + heart)
  3665. elif term == "panda":
  3666. bot.sendMessage(chat_id,
  3667. "*Panda:*\n\nPanda is an emotional crybaby but she is also heartless and has _no_ feelings. Other than that, she is a good friend to people who deserve it.",
  3668. parse_mode="markdown")
  3669. elif term == "alla":
  3670. bot.sendMessage(chat_id,
  3671. "*Ella:*\n\nElla is very unpredictable. She is the sweetest meanest person you'll ever meet. Sometimes she does things she can't even understand herself, but she isn't stupid. She can also be a harsh and ruthless mean bitch if she wants to, but naturally she is sweet to all.",
  3672. parse_mode="markdown")
  3673. elif term == "awais":
  3674. bot.sendMessage(chat_id,
  3675. "*Awais:*\n\nOne word. Telegod.",
  3676. parse_mode="markdown")
  3677. else:
  3678. term = str(message.lower()[4:]).title()
  3679. try:
  3680. definition = urbandict.define(term)[0]['def']
  3681. except:
  3682. definition = urbandict.define(term)[0]['def']
  3683. try:
  3684. example1 = urbandict.define(term)[0]['example']
  3685. except:
  3686. example1 = 'None'
  3687. try:
  3688. example2 = urbandict.define(term)[1]['example']
  3689. except:
  3690. example2 = "None/"
  3691. if len(example2) > 275:
  3692. bot.sendMessage(chat_id, "*" + term + "*:\n\n" + definition + '\n\n_1.) ' + example1 + '_', parse_mode="markdown")
  3693. else:
  3694. bot.sendMessage(chat_id,
  3695. "*" + term + "*:\n\n" + definition + '\n\n_1.) ' + example1 + '\n2.) ' + example2 + '_',
  3696. parse_mode="markdown")
  3697. if "/ud " in message:
  3698. t = threading.Thread(target=define)
  3699. term = msg['text'][4:]
  3700. t.start()
  3701. slapr = ['$q was split from crotch to sternum by $w.', "$q was busted.", '$q was exposed by $w.', "$q was sawn in half by $w.", "$q fell out of the world.", "$q was killed by $w using magic.", "$q fell off a ladder.", "$q withered away.", "$w put $q in check-mate.", "$q played hot-potato with a grenade.", "$q was axe-murdered by $w", "$q was squashed by a falling anvil.", "$q has encountered an error", "$w slapped $q with pure nothing", "$q escaped infection by dying.", "$q suffocated in a wall.", "$q was terminated by $w.", "$q was not invincible.", "$q got finished off by $w", "$q fell from a high place because of $w.", "$q was knocked into the void by $w", "$w threw $q off a building."]
  3702. slap = ['$q was split from crotch to sternum.', "$q got exposed.", "$q was busted.", "$q was sawn in half.", "$q fell out of the world.", "$q was killed by magic.", "$q fell off a ladder.", "$q withered away.", "$q was put in check-mate.", "$q played hot-potato with a grenade.", "$q was axe-murdered", "$q was squashed by a falling anvil.", "$q has encountered an error", "$q was slapped with pure nothing", "$q escaped infection by dying.", "$q suffocated in a wall.", "$q was terminated", "$q was not invincible.", "$q got finished off", "$q fell from a high place", "$q was knocked into the void", "$q was thrown off a building."]
  3703. if "/google " in message:
  3704. google = msg['text'][8:]
  3705. bot.sendMessage(chat_id, "[" + str(google) + "](https://www.google.com/#q=" + str(google).replace(" ",
  3706. "+") + ")",
  3707. parse_mode="markdown", disable_web_page_preview=True)
  3708. if "/slap" in message:
  3709. if "reply_to_message" in msg:
  3710. if os.path.isfile("data/n" + str(messageFromID) + ".txt") == False:
  3711. name = str(msg['from']['first_name'])
  3712. else:
  3713. name = str(open("data/n" + str(messageFromID) + ".txt").read())
  3714. if os.path.isfile("data/n" + str(msg['reply_to_message']['from']['id']) + ".txt") == False:
  3715. namer = str(msg['reply_to_message']['from']['first_name'])
  3716. else:
  3717. namer = str(open("data/n" + str(msg['reply_to_message']['from']['id']) + ".txt").read())
  3718. bot.sendMessage(chat_id, str(random.choice(slapr)).replace("$q", namer).replace("$w", name), reply_to_message_id=msg['message_id'])
  3719. else:
  3720. if os.path.isfile("data/n" + str(messageFromID) + ".txt") == False:
  3721. name = str(msg['from']['first_name'])
  3722. else:
  3723. name = str(open("data/n" + str(messageFromID) + ".txt").read())
  3724. bot.sendMessage(chat_id, str(random.choice(slap)).replace("$q", name), reply_to_message_id=msg['message_id'])
  3725. if message == '/def':
  3726. bot.sendMessage(chat_id, "Usage: /def <term>")
  3727. if messageType != 'private':
  3728. if "/scramble" in message:
  3729. if "True" in open(str(chat_id) + "/data/games.txt", "r").read():
  3730. if "False" in open(str(chat_id) + "/data/scramble.txt", "r").read():
  3731. open(str(chat_id) + "/data/scramble.txt", "w").write('True')
  3732. else:
  3733. bot.sendMessage(chat_id, "Game in progress!!")
  3734.  
  3735. if "/type" in message:
  3736. if "True" in open(str(chat_id) + "/data/games.txt", "r").read():
  3737. if "False" in open(str(chat_id) + "/data/type.txt", "r").read():
  3738. open(str(chat_id) + "/data/type.txt", "w").write('True')
  3739. else:
  3740. bot.sendMessage(chat_id, "Game in progress!!")
  3741.  
  3742. def scramble():
  3743. open(str(chat_id) + "/data/scramble.txt", "w").write('inprogress')
  3744. #current_chat_id = str(open(str(chat_id) + "/data/currentchat.txt", "w").write(str(chat_id)))
  3745. rw = RandomWords()
  3746. global word
  3747. word = rw.random_word()
  3748. open(str(chat_id) + "/data/word.txt", "w").write(str(word))
  3749. words = ''.join(random.sample(word, len(word)))
  3750. bot.sendMessage(chat_id, "The word to unscramble is:\n*" + str(words) + "*", parse_mode="markdown")
  3751. print(word)
  3752. endTime = datetime.datetime.now() + datetime.timedelta(seconds=int(open(str(chat_id) + "/data/gamelimit.txt").read()))
  3753. while True:
  3754. if "inprogress" in open(str(chat_id) + "/data/scramble.txt", "r").read():
  3755. if datetime.datetime.now() >= endTime:
  3756. bot.sendMessage(chat_id, "Times up word is *" + str(open(str(chat_id) + "/data/word.txt").read()) + "*", parse_mode="markdown")
  3757. open(str(chat_id) + "/data/scramble.txt", "w").write('False')
  3758. break
  3759. else:
  3760. break
  3761. def type():
  3762. open(str(chat_id) + "/data/type.txt", "w").write('inprogress')
  3763. #current_chat_id = str(open(str(chat_id) + "/data/currentchat.txt", "w").write(str(chat_id)))
  3764. rw = RandomWords()
  3765. global word
  3766. word = rw.random_word()
  3767. open(str(chat_id) + "/data/typeword.txt", "w").write(str(word))
  3768. global start
  3769. start = time.time()
  3770. bot.sendMessage(chat_id, "The word to type is:\n*" + str(word) + "*", parse_mode="markdown")
  3771. print(word)
  3772. endTime = datetime.datetime.now() + datetime.timedelta(seconds=int(open(str(chat_id) + "/data/gamelimit.txt").read()))
  3773. while True:
  3774. if "inprogress" in open(str(chat_id) + "/data/type.txt", "r").read():
  3775. if datetime.datetime.now() >= endTime:
  3776. bot.sendMessage(chat_id, "You took too long to type *" + str(open(str(chat_id) + "/data/typeword.txt").read()) + "*!", parse_mode="markdown")
  3777. open(str(chat_id) + "/data/type.txt", "w").write('False')
  3778. break
  3779. else:
  3780. break
  3781. if messageType != 'private':
  3782. if "True" in open(str(chat_id) + "/data/scramble.txt", "r").read():
  3783. t = threading.Thread(target=scramble)
  3784. t.start()
  3785. if "True" in open(str(chat_id) + "/data/type.txt", "r").read():
  3786. t = threading.Thread(target=type)
  3787. print(threading.activeCount())
  3788. t.start()
  3789. if "inprogress" in open(str(chat_id) + "/data/scramble.txt", "r").read():
  3790. if open(str(chat_id) + "/data/word.txt").read() in message:
  3791. write = int(
  3792. str(open("rooms/" + str(messageFromID) + "money.txt", "r").readlines()).replace("[",
  3793. "").replace(
  3794. "'", "").replace("]", "")) + int(len(str(open(str(chat_id) + "/data/word.txt").read())) * 1)
  3795. write2 = int(
  3796. str(open("rooms/" + str(messageFromID) + "wins.txt", "r").readlines()).replace("[",
  3797. "").replace(
  3798. "'", "").replace("]", "")) + int(1)
  3799. bot.sendMessage(chat_id, str(msg['from']['first_name']) + " wins!")
  3800. open("rooms/" + str(messageFromID) + "wins.txt", "w").write(str(write2))
  3801. open(str(chat_id) + "/data/scramble.txt", "w").write('False')
  3802. open("rooms/" + str(messageFromID) + "money.txt", "w").write(str(write))
  3803. if 'inprogress' in open(str(chat_id) + '/data/type.txt', 'r').read():
  3804. print('THIS IS IT: ' + open(str(chat_id) + "/data/typeword.txt").read() + ' == ' + message)
  3805.  
  3806. if '/type' in message:
  3807. pass
  3808. elif open(str(chat_id) + "/data/typeword.txt").read() in message:
  3809. end = time.time()
  3810. write = int(
  3811. str(open("rooms/" + str(messageFromID) + "money.txt", "r").readlines()).replace("[",
  3812. "").replace(
  3813. "'", "").replace("]", "")) + int(len(word) * 1)
  3814. write2 = int(
  3815. str(open("rooms/" + str(messageFromID) + "wins.txt", "r").readlines()).replace("[",
  3816. "").replace(
  3817. "'", "").replace("]", "")) + int(1)
  3818. bot.sendMessage(chat_id, str(msg['from']['first_name']) + " wins! Took " + str(str(start-end)).replace('-', '')[:4] + ' seconds.')
  3819. open("rooms/" + str(messageFromID) + "wins.txt", "w").write(str(write2))
  3820. open(str(chat_id) + "/data/type.txt", "w").write('False')
  3821. open(str(chat_id) + "/data/typeword.txt", "w").write('zaprt')
  3822. open("rooms/" + str(messageFromID) + "money.txt", "w").write(str(write))
  3823. with open(str(chat_id) + '/data/blacklisted.txt', 'r') as f:
  3824. for line in f:
  3825. blackLISTED = str('\n'.join([x for x in line.split("\n") if x.strip() != ''])).split('\n')
  3826. if any (s in message.lower() for s in blackLISTED):
  3827. if str(msg['from']['id']) in open(str(chat_id) + "/data/admin.txt", "r").read():
  3828. ()
  3829. elif str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  3830. ()
  3831. else:
  3832. if chat_id == -1001120893205:
  3833. ()
  3834. else:
  3835. bot.sendMessage(chat_id, str(msg['from']['first_name']) + ' has been kicked for saying a blacklisted word.')
  3836. bot.kickChatMember(chat_id, str(msg['from']['id']))
  3837. #if messageType != 'private':
  3838. #if "/state" in message:
  3839. # if "True" in open(str(chat_id) + "/data/games.txt", "r").read():
  3840. # if "False" in open(str(chat_id) + "/data/state.txt", "r").read():
  3841. # open(str(chat_id) + "/data/state.txt", "w").write('True')
  3842. # else:
  3843. # bot.sendMessage(chat_id, "Game in progress!!")
  3844.  
  3845. def state():
  3846. open(str(chat_id) + "/data/state.txt", "w").write('inprogress')
  3847. global statename
  3848. statename = ['alabama', 'alaska', 'arizona', 'arkansas', 'california', 'colorado', 'connecticut', 'delaware', 'florida', 'georgia', 'hawaii', 'idaho', 'illinois', 'indiana', 'iowa', 'kansas', 'kentucky', 'louisiana', 'maine', 'maryland', 'massachusetts', 'michigan', 'minnesota', 'mississippi', 'missouri', 'montana', 'nebraska', 'nevada', 'new-hampshire', 'new-jersey', 'new-mexico', 'new-york', 'north-carolina', 'north-dakota', 'ohio', 'oklahoma', 'oregon', 'pennsylvania', 'rhode-island', 'south-carolina', 'south-dakota', 'tennessee', 'texas', 'utah', 'vermont', 'virginia', 'washington', 'west-virginia', 'wisconsin', 'wyoming']
  3849. randomstate = random.choice(statename)
  3850. open(str(chat_id) + "/data/statename.txt", "w").write(str(randomstate).replace('-', ' '))
  3851. bot.sendPhoto(chat_id, open("states/" + str(randomstate) + ".jpg", "rb"))
  3852. print(open(str(chat_id) + "/data/statename.txt", "r").read())
  3853. endTime = datetime.datetime.now() + datetime.timedelta(seconds=int(open(str(chat_id) + "/data/gamelimit.txt").read()))
  3854. while True:
  3855. if "inprogress" in open(str(chat_id) + "/data/state.txt", "r").read():
  3856. if datetime.datetime.now() >= endTime:
  3857. bot.sendMessage(chat_id, "Times up, the state is *" + str(randomstate) + "*", parse_mode="markdown")
  3858. open(str(chat_id) + "/data/state.txt", "w").write('False')
  3859. break
  3860. else:
  3861. break
  3862. if messageType != 'private':
  3863. if "True" in open(str(chat_id) + "/data/state.txt", "r").read():
  3864. t = threading.Thread(target=state)
  3865. t.start()
  3866. if "inprogress" in open(str(chat_id) + "/data/state.txt", "r").read():
  3867. if open(str(chat_id) + "/data/statename.txt", "r").read() in message:
  3868. write = int(
  3869. str(open("rooms/" + str(messageFromID) + "money.txt", "r").readlines()).replace("[",
  3870. "").replace(
  3871. "'", "").replace("]", "")) + 10
  3872. write2 = int(
  3873. str(open("rooms/" + str(messageFromID) + "wins.txt", "r").readlines()).replace("[",
  3874. "").replace(
  3875. "'", "").replace("]", "")) + int(1)
  3876. bot.sendMessage(chat_id, str(msg['from']['first_name']) + " wins!")
  3877. open("rooms/" + str(messageFromID) + "wins.txt", "w").write(str(write2))
  3878. open(str(chat_id) + "/data/state.txt", "w").write('False')
  3879. open("rooms/" + str(messageFromID) + "money.txt", "w").write(str(write))
  3880. if message in commandsList:
  3881. if message in message:
  3882. cont = True
  3883. if cont:
  3884. if message == "hey bot":
  3885. if os.path.isfile("data/n" + str(messageFromID) + ".txt") == False:
  3886. bot.sendMessage(chat_id, "Hi, " + msg['from']['first_name'][:15] + "!")
  3887. else:
  3888. bot.sendMessage(chat_id, "Hi, " + open("data/n" + str(messageFromID) + ".txt").read() + "!")
  3889. def picturemessage():
  3890. Bot.send_chat_action(chat_id, action=telegram.ChatAction.TYPING)
  3891. try:
  3892. color = open(str(chat_id) + "/data/imagecolor.txt").read()
  3893. color1 = open(str(chat_id) + "/data/textcolor.txt").read()
  3894. profiles = bot.getUserProfilePhotos(msg['new_chat_member']['id'])
  3895. file_id = profiles['photos'][0][-1]['file_id']
  3896. filename = str(msg['new_chat_member']['id']) + ".jpg"
  3897. bot.download_file(file_id, filename)
  3898. im = Image.open(filename)
  3899. img = PIL.Image.new("RGB", (640, 800), (color))
  3900. draw = PIL.ImageDraw.Draw(img)
  3901. font = ImageFont.truetype("comic.ttf", int("65"))
  3902. except:
  3903. filename = "NoPFP.jpg"
  3904. im = Image.open(filename)
  3905. img = Image.new("RGB", (640, 800), (color))
  3906. draw = PIL.ImageDraw.Draw(img)
  3907. font = ImageFont.truetype("comic.ttf", int("65"))
  3908. if os.path.isfile("data/n" + str(msg["new_chat_member"]['id']) + ".txt") == False:
  3909. if len(msg['from']['first_name']) > 15:
  3910. line2 = msg["new_chat_member"]['first_name'][:15] + "...!"
  3911. else:
  3912. line2 = msg['new_chat_member']['first_name'] + "!"
  3913. else:
  3914. if len(open("data/n" + str(msg["new_chat_member"]['id']) + ".txt").read()) > 15:
  3915. line2 = open("data/n" + str(msg["new_chat_member"]['id']) + ".txt").read()[:15] + "...!"
  3916. else:
  3917. line2 = open("data/n" + str(msg["new_chat_member"]['id']) + ".txt").read() + "!"
  3918. if os.path.isfile(str(chat_id) + "/data/greettext.txt") == False:
  3919. line1 = "Welcome"
  3920. else:
  3921. line1 = str(open(str(chat_id) + "/data/greettext.txt").read())
  3922. w, h = font.getsize(line1)
  3923. w2, h2 = font.getsize(line2)
  3924. draw.text(((650 - w) / 2, (1360 - h) / 2), line1, font=font, fill=str(color1))
  3925. draw.text(((650 - w2) / 2, ((1300 - h2) / 2) + 100), line2, font=font, fill=str(color1))
  3926. img.paste(im, (0, 0))
  3927. img.save("1" + filename)
  3928. bot.sendPhoto(chat_id, open("1" + filename, "rb"))
  3929. os.remove("1" + filename)
  3930. if filename != "NoPFP.jpg":
  3931. os.remove(filename)
  3932. if 'new_chat_member' in msg:
  3933. if 'username' in msg:
  3934. newuser = str("@" + msg['new_chat_member']['username'])
  3935. else:
  3936. newuser = msg['from']['first_name']
  3937. if 'new_chat_member' in msg:
  3938. newuser = msg['new_chat_member']['first_name']
  3939. print(msg['new_chat_member']['first_name'], "has joined", msg['chat']['title'])
  3940. if msg['new_chat_member']['id'] == botID:
  3941. bot.sendMessage(chat_id, "Hi, I am currently in beta. So if there are any bugs, PM @spoon xoxo")
  3942. else:
  3943. if 'True' in open(str(chat_id) + "/data/lock.txt").read():
  3944. bot.kickChatMember(chat_id, msg['new_chat_member']['id'])
  3945. bot.sendMessage(chat_id, "This group is currently locked. /lock to unlock.")
  3946. else:
  3947. if 'True' in open(str(chat_id) + "/data/antibot.txt").read():
  3948. try:
  3949. if str(msg['new_chat_member']['username']).lower().endswith('bot'):
  3950. bot.kickChatMember(chat_id, msg['new_chat_member']['id'])
  3951. bot.sendMessage(chat_id, "Anti-bot is activated, sorry.")
  3952. except:
  3953. ()
  3954. else:
  3955. if 'True' in open(str(chat_id) + "/wel.txt").read():
  3956. if "Text" in open(str(chat_id) + "/data/greet.txt").read():
  3957. if os.path.isfile(str(chat_id) + "/welcome.txt") == False:
  3958. bot.sendMessage(chat_id,
  3959. "Welcome to the group! The welcome message has not been set. Type '/wel' and then your message. For more help, type /wel")
  3960. else:
  3961. if os.path.isfile("data/n" + str(msg['new_chat_member']['id']) + ".txt") == False:
  3962. f = open(str(chat_id) + "/welcome.txt").read().replace("$n",
  3963. msg['new_chat_member'][
  3964. 'first_name']).replace(
  3965. "$u",
  3966. newuser).replace("$t", msg['chat']['title'])
  3967. bot.sendMessage(chat_id, str(f))
  3968. else:
  3969. f = open(str(chat_id) + "/welcome.txt").read().replace("$n",
  3970. open("data/n" + str(
  3971. msg['new_chat_member']['id']) + ".txt").read()).replace(
  3972. "$u",
  3973. newuser).replace("$t", msg['chat']['title'])
  3974. bot.sendMessage(chat_id, str(f))
  3975. else:
  3976. t = threading.Thread(target=picturemessage)
  3977. t.start()
  3978. else:
  3979. if 'True' in open(str(chat_id) + "/wel.txt").read():
  3980. if "Text" in open(str(chat_id) + "/data/greet.txt").read():
  3981. if os.path.isfile(str(chat_id) + "/welcome.txt") == False:
  3982. bot.sendMessage(chat_id,
  3983. "Welcome to the group! The welcome message has not been set. Type '/wel' and then your message. For more help, type /wel")
  3984. else:
  3985. if os.path.isfile("data/n" + str(msg['new_chat_member']['id']) + ".txt") == False:
  3986. f = open(str(chat_id) + "/welcome.txt").read().replace("$n",
  3987. msg['new_chat_member'][
  3988. 'first_name']).replace(
  3989. "$u",
  3990. newuser).replace("$t", msg['chat']['title'])
  3991. bot.sendMessage(chat_id, str(f))
  3992. else:
  3993. f = open(str(chat_id) + "/welcome.txt").read().replace("$n",
  3994. open("data/n" + str(
  3995. msg['new_chat_member'][
  3996. 'id']) + ".txt").read()).replace(
  3997. "$u",
  3998. newuser).replace("$t", msg['chat']['title'])
  3999. bot.sendMessage(chat_id, str(f))
  4000. else:
  4001. t = threading.Thread(target=picturemessage)
  4002. t.start()
  4003. def check():
  4004. if str(msg['from']['id']) in open(str(chat_id) + "/data/adminlist.data", "r").read():
  4005. f = threading.Thread(target=admincom)
  4006. f.start()
  4007. print(threading.active_count())
  4008. if messageType != 'private':
  4009. t = threading.Thread(target=check)
  4010. t.start()
  4011. if "/callme " in message:
  4012. if len(message[8:]) > 25:
  4013. bot.sendMessage(chat_id, "The limit is 25 characters!")
  4014. elif "nothing" in message:
  4015. if os.path.isfile("data/n" + str(messageFromID) + ".txt") == False:
  4016. bot.sendMessage(chat_id, "You currently have no nicknames, and I won't call you nothing :(")
  4017. else:
  4018. bot.sendMessage(chat_id, "Okay, I won't call you by any nicknames.")
  4019. os.remove("data/n" + str(messageFromID) + ".txt")
  4020. else:
  4021. if "\u2B50" in message:
  4022. bot.sendMessage(chat_id, "You are trying to put a restricted emoji your name. This star is only for admins, please retry.")
  4023. else:
  4024. bot.sendMessage(chat_id, "Okay " + msg['text'][8:].replace(u"\u2B50", "") + ", I'll remember that.")
  4025. open("data/n" + str(messageFromID) + ".txt", "w").write(str(msg['text'][8:]).replace(u"\u2B50", ""))
  4026.  
  4027. if "/me" in message:
  4028. if messageType != 'private':
  4029. with open(str(chat_id) + "/data/numberone.txt", "r") as one:
  4030. for _ in range(1):
  4031. OwnerMessage = one.readline()
  4032. with open(str(chat_id) + "/data/numbertwo.txt", "r") as two:
  4033. for _ in range(1):
  4034. OwnerCoins = two.readline()
  4035. with open(str(chat_id) + "/data/numberthree.txt", "r") as three:
  4036. for _ in range(1):
  4037. OwnerWins = three.readline()
  4038.  
  4039. if '@' in msg['text']:
  4040. with open("data/listofusers.data", 'r') as f:
  4041. lines = f.read().split("\n")
  4042.  
  4043. # print("Number of lines is {}".format(len(lines)))
  4044. if '@' in msg['text'][4:]:
  4045. word = str(msg['text'][4:]).replace('@', "").lower()
  4046. else:
  4047. word = str(msg['text'][4:]).lower()
  4048.  
  4049. # iterate over lines, and print out line numbers which contain
  4050. # the word of interest.
  4051. for i, line in enumerate(lines):
  4052. if word in line.lower(): # or word in line.split() to search for full words
  4053. # print("Word \"{}\" found in line {}".format(word, i + 1))
  4054. foundLine = i
  4055. f = open("data/listofusers.data")
  4056. lines = f.readlines()
  4057. meProfileUser = lines[i].split(">:>")[0]
  4058. meProfileName = lines[i].split(">:>")[1].replace('\n', '')
  4059.  
  4060. if str(meProfileUser) in OwnerMessage:
  4061. mostMessages = "\nMost Messages Sent \U0001F947"
  4062. else:
  4063. mostMessages = ""
  4064. if str(meProfileUser) in OwnerWins:
  4065. mostWins = "\nMost Wins \U0001F947"
  4066. else:
  4067. mostWins = ""
  4068. if str(meProfileUser) in OwnerCoins:
  4069. mostCoins = "\nMost Coins \U0001F947"
  4070. else:
  4071. mostCoins = ""
  4072. if meProfileUser in open(chat_id + '/data/adminlist.data', 'r').read():
  4073. star = u"\u2B50"
  4074. else:
  4075. if str(meProfileUser) in open(str(chat_id) + "/data/admin.txt").read():
  4076. star = u"\u2B50"
  4077. else:
  4078. star = ""
  4079. if " help" in message:
  4080. bot.sendMessage(chat_id,
  4081. "You can add links to your /me message by sending this:\n/me instagram <instagram username>\n/me time <location for time>\n/me reddit <reddit username>\n/me steam <steam username>\n/me location <location>\n/me snapchat <snapchat>\n/me soundcloud <soundcloud>")
  4082. if " instagram " in message:
  4083. if "delete" in msg['text'][14:].lower():
  4084. os.remove("data/insta" + str(meProfileUser) + ".txt")
  4085. bot.sendMessage(chat_id, "Instagram removed!")
  4086. else:
  4087. if len(msg['text'][14:].lower()) > 15:
  4088. bot.sendMessage(chat_id, "Not a valid Instagram name.")
  4089. else:
  4090. open("data/insta" + str(meProfileUser) + ".txt", "w").write(
  4091. str(msg['text'][14:]))
  4092. bot.sendMessage(chat_id, "Instagram set!")
  4093. if " time " in message:
  4094.  
  4095. if "delete" in msg['text'][9:].lower():
  4096. os.remove("data/time" + str(meProfileUser) + ".txt")
  4097. bot.sendMessage(chat_id, "Time removed!")
  4098. else:
  4099. tf = timezonefinder.TimezoneFinder()
  4100. geo_keys = ['AIzaSyC9CNdTPQGkmm2Wq6e3e-DnC96lNTsdp8s']
  4101. geolocator = geocoders.GoogleV3(api_key=random.choice(geo_keys))
  4102. try:
  4103. place, (lat, lng) = geolocator.geocode(
  4104. msg['text'][9:])
  4105. open("data/time" + str(meProfileUser) + ".txt", 'w').write(msg['text'][9:])
  4106. timezone_str = tf.certain_timezone_at(lat=lat, lng=lng)
  4107. location = timezone(str(timezone_str))
  4108. location_time = datetime.datetime.now(location)
  4109. userTime = str("Current Time: *" + location_time.strftime('%I:%M %p') + "*\n")
  4110. bot.sendMessage(chat_id, 'Set time!')
  4111. except:
  4112. bot.sendMessage(chat_id, 'Not a valid location!')
  4113. if " psn " in message:
  4114. if "delete" in msg['text'][8:].lower():
  4115. os.remove("data/psn" + str(meProfileUser) + ".txt")
  4116. bot.sendMessage(chat_id, "PlayStation removed!")
  4117. else:
  4118. if len(msg['text'][8:].lower()) > 16:
  4119. bot.sendMessage(chat_id, "Not a valid PlayStation name.")
  4120. else:
  4121. open("data/psn" + str(meProfileUser) + ".txt",
  4122. "w").write(
  4123. str(msg['text'][8:]))
  4124. bot.sendMessage(chat_id, "PlayStation set!")
  4125. if " xbox " in message:
  4126. if "delete" in msg['text'][9:].lower():
  4127. os.remove("data/xbox" + str(meProfileUser) + ".txt")
  4128. bot.sendMessage(chat_id, "Xbox removed!")
  4129. else:
  4130. if len(msg['text'][9].lower()) > 15:
  4131. bot.sendMessage(chat_id, "Not a valid Xbox name.")
  4132. else:
  4133. open("data/xbox" + str(meProfileUser) + ".txt",
  4134. "w").write(
  4135. str(msg['text'][9:]))
  4136. bot.sendMessage(chat_id, "Xbox set!")
  4137. if " lock" in message:
  4138. if "True" in open(str("data/locked" + str(meProfileUser) + ".txt"), "r"):
  4139. open("data/locked" + str(meProfileUser) + ".txt", "w").write("False")
  4140. bot.sendMessage(chat_id,
  4141. "Your /me profile has been unlocked, anyone who replies to your message with /me will be able to see it!")
  4142. else:
  4143. open("data/locked" + str(meProfileUser) + ".txt", "w").write("True")
  4144. bot.sendMessage(chat_id,
  4145. "Your /me profile has been locked, anyone who replies to your message with /me will not be able to see it!")
  4146. if " reddit " in message:
  4147. if "delete" in msg['text'][11:].lower():
  4148. os.remove("data/red" + str(meProfileUser) + ".txt")
  4149. bot.sendMessage(chat_id, "Reddit removed!")
  4150. else:
  4151. if len(msg['text'][11:].lower()) > 15:
  4152. bot.sendMessage(chat_id, "Not a valid Reddit name.")
  4153. else:
  4154. open("data/red" + str(meProfileUser) + ".txt", "w").write(
  4155. str(msg['text'][11:]))
  4156. bot.sendMessage(chat_id, "Reddit set!")
  4157. if " steam " in message:
  4158. if "delete" in msg['text'][10:].lower():
  4159. os.remove("data/steam" + str(meProfileUser) + ".txt")
  4160. bot.sendMessage(chat_id, "Steam removed!")
  4161. else:
  4162. if len(msg['text'][10:].lower()) > 20:
  4163. bot.sendMessage(chat_id, "Not a valid Steam name.")
  4164. else:
  4165. open("data/steam" + str(meProfileUser) + ".txt", "w").write(
  4166. str(msg['text'][10:]))
  4167. bot.sendMessage(chat_id, "Steam set!")
  4168. if " soundcloud " in message:
  4169. if "delete" in msg['text'][15:].lower():
  4170. os.remove("data/soundcloud" + str(meProfileUser) + ".txt")
  4171. bot.sendMessage(chat_id, "Steam removed!")
  4172. else:
  4173. if len(msg['text'][15:].lower()) > 20:
  4174. bot.sendMessage(chat_id, "Not a valid Soundcloud name.")
  4175. else:
  4176. open("data/soundcloud" + str(meProfileUser) + ".txt", "w").write(
  4177. str(msg['text'][15:]))
  4178. bot.sendMessage(chat_id, "Soundcloud set!")
  4179. if " snapchat " in message:
  4180. if "delete" in msg['text'][13:].lower():
  4181. os.remove("data/snapchat" + str(meProfileUser) + ".txt")
  4182. bot.sendMessage(chat_id, "Snapchat removed!")
  4183. else:
  4184. if len(msg['text'][13:].lower()) > 15:
  4185. bot.sendMessage(chat_id, "Not a valid Snapchat name.")
  4186. else:
  4187. open("data/snapchat" + str(meProfileUser) + ".txt", "w").write(
  4188. str(msg['text'][13:]))
  4189. bot.sendMessage(chat_id, "Snapchat set!")
  4190.  
  4191. if os.path.isfile(("data/soundcloud" + str(meProfileUser) + ".txt")) == True:
  4192. Soundcloud = str("Soundcloud: [" + str(
  4193. open("data/soundcloud" + str(meProfileUser) + ".txt",
  4194. "r").read()) + "](https://soundcloud.com/" + str(
  4195. open("data/soundcloud" + str(meProfileUser) + ".txt",
  4196. "r").read()) + ")\n")
  4197. else:
  4198. Soundcloud = ""
  4199. if os.path.isfile(("data/snapchat" + str(meProfileUser) + ".txt")) == True:
  4200. Snapchat = str("Snapchat: [" + str(
  4201. open("data/snapchat" + str(meProfileUser) + ".txt",
  4202. "r").read()) + "](https://www.snapchat.com/add/" + str(
  4203. open("data/snapchat" + str(meProfileUser) + ".txt",
  4204. "r").read()) + ")\n")
  4205. else:
  4206. Snapchat = ""
  4207. if " location " in message:
  4208. if "delete" in msg['text'][13].lower():
  4209. os.remove("data/loc" + str(meProfileUser) + ".txt")
  4210. bot.sendMessage(chat_id, "Location removed!")
  4211. else:
  4212. if len(msg['text'][13:].lower()) > 30:
  4213. bot.sendMessage(chat_id, "Not a valid Location name.")
  4214. else:
  4215. open("data/loc" + str(meProfileUser) + ".txt", "w").write(
  4216. str(msg['text'][13:]))
  4217. bot.sendMessage(chat_id, "Location set!")
  4218. if os.path.isfile(("data/insta" + str(meProfileUser) + ".txt")) == True:
  4219. Instagram = str(
  4220. "Instagram: [" + str(open("data/insta" + str(meProfileUser) + ".txt",
  4221. "r").read()) + "](https://www.instagram.com/" + str(
  4222. open("data/insta" + str(meProfileUser) + ".txt", "r").read()) + ")\n")
  4223. else:
  4224. Instagram = ""
  4225. if os.path.isfile(("data/steam" + str(meProfileUser) + ".txt")) == True:
  4226. Steam = str("Steam: [" + str(open("data/steam" + str(meProfileUser) + ".txt",
  4227. "r").read()) + "](http://steamcommunity.com/id/" + str(
  4228. open("data/steam" + str(meProfileUser) + ".txt", "r").read()) + ")\n")
  4229. else:
  4230. Steam = ""
  4231. if os.path.isfile(("data/xbox" + str(meProfileUser) + ".txt")) == True:
  4232. XBOX = str("Xbox: [" + str(open("data/xbox" + str(meProfileUser) + ".txt",
  4233. "r").read()) + "](http://live.xbox.com/en-US/Profile?gamertag=" + str(
  4234. open("data/xbox" + str(meProfileUser) + ".txt", "r").read()).replace(" ",
  4235. "+") + ")\n")
  4236. else:
  4237. XBOX = ""
  4238. if os.path.isfile(("data/red" + str(meProfileUser) + ".txt")) == True:
  4239. Reddit = str("Reddit: [" + str(open("data/red" + str(meProfileUser) + ".txt",
  4240. "r").read()) + "](https://www.reddit.com/user/" + str(
  4241. open("data/red" + str(meProfileUser) + ".txt", "r").read()) + ")\n")
  4242. else:
  4243. Reddit = ""
  4244. if os.path.isfile(("data/loc" + str(meProfileUser) + ".txt")) == True:
  4245. Location = str("Location: [" + str(open("data/loc" + str(meProfileUser) + ".txt",
  4246. "r").read()) + "](https://www.google.com/#q=" + str(
  4247. open("data/loc" + str(meProfileUser) + ".txt", "r").read()).replace(" ",
  4248. "+") + ")\n")
  4249. else:
  4250. Location = ""
  4251. if os.path.isfile(("data/psn" + str(meProfileUser) + ".txt")) == True:
  4252. PSN = str("PSN: [" + str(open("data/psn" + str(meProfileUser) + ".txt",
  4253. "r").read()) + "](https://my.playstation.com/" + str(
  4254. open("data/psn" + str(meProfileUser) + ".txt", "r").read()).replace(" ",
  4255. "+") + ")\n")
  4256. else:
  4257. PSN = ""
  4258. if os.path.isfile(str(chat_id) + "/data/" + str(meProfileUser) + ".txt") == True:
  4259. Warns = str(
  4260. "Amount of warns: *(" + str(open(str(chat_id) + "/data/" + str(meProfileUser) + ".txt",
  4261. "r").read()) + "/3)*\n")
  4262. else:
  4263. Warns = ""
  4264. if os.path.isfile(("data/time" + str(meProfileUser) + ".txt")) == True:
  4265. tf = timezonefinder.TimezoneFinder()
  4266. geo_keys = ['AIzaSyC9CNdTPQGkmm2Wq6e3e-DnC96lNTsdp8s']
  4267. geolocator = geocoders.GoogleV3(api_key=random.choice(geo_keys))
  4268.  
  4269. place, (lat, lng) = geolocator.geocode(
  4270. str(open("data/time" + str(meProfileUser) + ".txt", 'r').read()))
  4271. timezone_str = tf.certain_timezone_at(lat=lat, lng=lng)
  4272. location = timezone(str(timezone_str))
  4273. location_time = datetime.datetime.now(location)
  4274. userTime = str("Current Time: *" + location_time.strftime('%I:%M %p') + "*\n")
  4275. else:
  4276. userTime = ""
  4277. usermessages = open(str(chat_id) + "/messages/" + str(meProfileUser) + ".txt", "r").read()
  4278. groupmessages = open(str(chat_id) + "/messagecount.txt", "r").read()
  4279. percentage = round((int(usermessages) / int(groupmessages)) * 100, 2)
  4280. print(percentage)
  4281. if os.path.isfile("data/n" + str(meProfileUser) + ".txt") == True:
  4282. name = open("data/n" + str(meProfileUser) + ".txt").read()
  4283. else:
  4284. name = meProfileName
  4285. print(name)
  4286. if "/me" in msg['text']:
  4287. print('yes')
  4288. bot.sendMessage(chat_id, "*" + name + " " + star + "*\n\nCoins: *" + str(
  4289. open("rooms/" + str(meProfileUser) + "money.txt",
  4290. "r").read()) + "\n*Wins: *" + str(
  4291. open("rooms/" + str(meProfileUser) + "wins.txt",
  4292. "r").read()) + str(mostCoins) + str(mostWins) + str(mostMessages) + "*\n%s%s%s%s%s%s%s%s%s%sYou've sent " % (
  4293. Warns, userTime,
  4294. Instagram, Reddit, Steam, Location, Soundcloud, Snapchat, PSN, XBOX) + open(
  4295. str(chat_id) +
  4296. "/messages/" + str(meProfileUser) + ".txt", "r").read() + " (" + str(
  4297. percentage) + "%) and this group has " + open(str(chat_id) + "/messagecount.txt",
  4298. "r").read() + " messages.",
  4299. parse_mode="markdown", disable_web_page_preview=True)
  4300. else:
  4301.  
  4302. if 'reply_to_message' in msg:
  4303. print(OwnerWins)
  4304. print(msg['reply_to_message']['from']['id'])
  4305. if str(msg['reply_to_message']['from']['id']) in OwnerMessage:
  4306. mostMessages = "\nMost Messages Sent \U0001F947"
  4307. else:
  4308. mostMessages = ""
  4309. if str(msg['reply_to_message']['from']['id']) in OwnerWins:
  4310. mostWins = "\nMost Wins \U0001F947"
  4311. else:
  4312. mostWins = ""
  4313. if str(msg['reply_to_message']['from']['id']) in OwnerCoins:
  4314. mostCoins = "\nMost Coins \U0001F947"
  4315. else:
  4316. mostCoins = ""
  4317. if str(msg['reply_to_message']['from']['id']) in open(chat_id + '/data/adminlist.data', 'r').read():
  4318. star = u"\u2B50"
  4319. else:
  4320. if str(msg['reply_to_message']['from']['id']) in open(str(chat_id) + "/data/admin.txt").read():
  4321. star = u"\u2B50"
  4322. else:
  4323. star = ""
  4324. if os.path.isfile("data/n" + str(msg['reply_to_message']['from']['id']) + ".txt") == True:
  4325. name = open("data/n" + str(msg['reply_to_message']['from']['id']) + ".txt").read()
  4326. else:
  4327. msg['from']['first_name'][:15]
  4328. if os.path.isfile(str(chat_id) + "/data/" + str(msg['reply_to_message']['from']['id']) + ".txt") == True:
  4329. Warns = str("Amount of warns: *(" + str(
  4330. open(str(chat_id) + "/data/" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4331. "r").read()) + "/3)*\n")
  4332. else:
  4333. Warns = ""
  4334. if os.path.isfile("data/n" + str(msg['reply_to_message']['from']['id']) + ".txt") == False:
  4335. if " help" in message:
  4336. bot.sendMessage(chat_id,
  4337. "You can add links to your /me message by sending this:\n/me instagram <instagram username>\n/me time <location for time>\n/me reddit <reddit username>\n/me steam <steam username>\n/me location <location>\n/me snapchat <snapchat>\n/me soundcloud <soundcloud>")
  4338. if os.path.isfile(
  4339. ("data/insta" + str(msg['reply_to_message']['from']['id']) + ".txt")) == True:
  4340. Instagram = str("Instagram: [" + str(
  4341. open("data/insta" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4342. "r").read()) + "](https://www.instagram.com/" + str(
  4343. open("data/insta" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4344. "r").read()) + ")\n")
  4345. else:
  4346. Instagram = ""
  4347. if os.path.isfile(
  4348. ("data/steam" + str(msg['reply_to_message']['from']['id']) + ".txt")) == True:
  4349. Steam = str("Steam: [" + str(
  4350. open("data/steam" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4351. "r").read()) + "](http://steamcommunity.com/id/" + str(
  4352. open("data/steam" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4353. "r").read()) + ")\n")
  4354. else:
  4355. Steam = ""
  4356. if os.path.isfile(
  4357. ("data/soundcloud" + str(msg['reply_to_message']['from']['id']) + ".txt")) == True:
  4358. Soundcloud = str("Soundcloud: [" + str(
  4359. open("data/soundcloud" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4360. "r").read()) + "](https://soundcloud.com/" + str(
  4361. open("data/soundcloud" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4362. "r").read()) + ")\n")
  4363. else:
  4364. Soundcloud = ""
  4365. if os.path.isfile(
  4366. ("data/red" + str(msg['reply_to_message']['from']['id']) + ".txt")) == True:
  4367. Reddit = str(
  4368. "Reddit: [" + str(
  4369. open("data/red" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4370. "r").read()) + "](https://www.reddit.com/user/" + str(
  4371. open("data/red" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4372. "r").read()) + ")\n")
  4373. else:
  4374. Reddit = ""
  4375. if os.path.isfile(
  4376. ("data/snapchat" + str(msg['reply_to_message']['from']['id']) + ".txt")) == True:
  4377. Snapchat = str("Snapchat: [" + str(
  4378. open("data/snapchat" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4379. "r").read()) + "](https://www.snapchat.com/add/" + str(
  4380. open("data/snapchat" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4381. "r").read()) + ")\n")
  4382. else:
  4383. Snapchat = ""
  4384. if os.path.isfile(("data/psn" + str(msg['reply_to_message']['from']['id']) + ".txt")) == True:
  4385. PSN = str("PSN: [" + str(open("data/psn" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4386. "r").read()) + "](https://my.playstation.com/" + str(
  4387. open("data/psn" + str(msg['reply_to_message']['from']['id']) + ".txt", "r").read()).replace(" ",
  4388. "+") + ")\n")
  4389. else:
  4390. PSN = ""
  4391. if os.path.isfile(("data/xbox" + str(msg['reply_to_message']['from']['id']) + ".txt")) == True:
  4392. XBOX = str("Xbox: [" + str(open("data/xbox" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4393. "r").read()) + "](http://live.xbox.com/en-US/Profile?gamertag=" + str(
  4394. open("data/xbox" + str(msg['reply_to_message']['from']['id']) + ".txt", "r").read()).replace(" ",
  4395. "+") + ")\n")
  4396. else:
  4397. XBOX = ""
  4398. if os.path.isfile(("data/time" + str(msg['reply_to_message']['from']['id']) + ".txt")) == True:
  4399. tf = timezonefinder.TimezoneFinder()
  4400. geo_keys = ['AIzaSyC9CNdTPQGkmm2Wq6e3e-DnC96lNTsdp8s']
  4401. geolocator = geocoders.GoogleV3(api_key=random.choice(geo_keys))
  4402.  
  4403. place, (lat, lng) = geolocator.geocode(
  4404. str(open("data/time" + str(msg['reply_to_message']['from']['id']) + ".txt", 'r').read()))
  4405. timezone_str = tf.certain_timezone_at(lat=lat, lng=lng)
  4406. location = timezone(str(timezone_str))
  4407. location_time = datetime.datetime.now(location)
  4408. userTime = str("Current Time: *" + location_time.strftime('%I:%M %p') + "*\n")
  4409. else:
  4410. userTime = ""
  4411. if os.path.isfile(
  4412. ("data/loc" + str(msg['reply_to_message']['from']['id']) + ".txt")) == True:
  4413. Location = str("Location: [" + str(
  4414. open("data/loc" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4415. "r").read()) + "](https://www.google.com/#q=" + str(
  4416. open("data/loc" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4417. "r").read()).replace(" ", "+") + ")\n")
  4418. else:
  4419. Location = ""
  4420. usermessages = open(str(chat_id) + "/messages/" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4421. "r").read()
  4422. groupmessages = open(str(chat_id) + "/messagecount.txt", "r").read()
  4423. percentage = round((int(usermessages) / int(groupmessages)) * 100, 2)
  4424. print(percentage)
  4425. if message == "/me":
  4426. if "False" in open(str("data/locked" + str(msg['reply_to_message']['from']['id']) + ".txt"), "r"):
  4427. bot.sendMessage(chat_id,
  4428. "*" + msg['reply_to_message']['from']['first_name'] + " " + star + "*\n\nCoins: *" + str(
  4429. open("rooms/" + str(msg['reply_to_message']['from']['id']) + "money.txt",
  4430. "r").read()) + "\n*Wins: *" + str(
  4431. open("rooms/" + str(msg['reply_to_message']['from']['id']) + "wins.txt",
  4432. "r").read()) + str(mostCoins) + str(mostWins) + str(mostMessages) + "*\n%s%s%s%s%s%s%s%s%s%sYou've sent " % (
  4433. Warns, userTime,
  4434. Instagram, Reddit, Steam, Location, Soundcloud, Snapchat, PSN, XBOX) + open(
  4435. str(chat_id) +
  4436. "/messages/" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4437. "r").read() + " (" + str(
  4438. percentage) + "%) and this group has " + open(
  4439. str(chat_id) + "/messagecount.txt",
  4440. "r").read() + " messages.",
  4441. parse_mode="markdown", disable_web_page_preview=True)
  4442. else:
  4443. bot.sendMessage(chat_id, "*" + msg['reply_to_message']['from']['first_name'] + " " + star + "*\n\nThis account is locked! \U0001F512",
  4444. parse_mode="markdown", disable_web_page_preview=True)
  4445. else:
  4446. if str(msg['reply_to_message']['from']['id']) in OwnerMessage:
  4447. mostMessages = "\nMost Messages Sent \U0001F947"
  4448. else:
  4449. mostMessages = ""
  4450. if str(msg['reply_to_message']['from']['id']) in OwnerWins:
  4451. mostWins = "\nMost Wins \U0001F947"
  4452. else:
  4453. mostWins = ""
  4454. if str(msg['reply_to_message']['from']['id']) in OwnerCoins:
  4455. mostCoins = "\nMost Coins \U0001F947"
  4456. else:
  4457. mostCoins = ""
  4458. if os.path.isfile(str(chat_id) + "/data/" + str(
  4459. msg['reply_to_message']['from']['id']) + ".txt") == True:
  4460. Warns = str(
  4461. "Amount of warns: *(" + str(
  4462. open(str(chat_id) + "/data/" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4463. "r").read()) + "/3)*\n")
  4464. else:
  4465. Warns = ""
  4466. if " help" in message:
  4467. bot.sendMessage(chat_id,
  4468. "You can add links to your /me message by sending this:\n/me instagram <instagram username>\n/me time <location for time>\n/me reddit <reddit username>\n/me steam <steam username>\n/me location <location>\n/me snapchat <snapchat>\n/me soundcloud <soundcloud>")
  4469. if os.path.isfile(
  4470. ("data/insta" + str(msg['reply_to_message']['from']['id']) + ".txt")) == True:
  4471. Instagram = str("Instagram: [" + str(
  4472. open("data/insta" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4473. "r").read()) + "](https://www.instagram.com/" + str(
  4474. open("data/insta" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4475. "r").read()) + ")\n")
  4476. else:
  4477. Instagram = ""
  4478. if os.path.isfile(("data/xbox" + str(msg['reply_to_message']['from']['id']) + ".txt")) == True:
  4479. XBOX = str("Xbox: [" + str(open("data/xbox" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4480. "r").read()) + "](http://live.xbox.com/en-US/Profile?gamertag=" + str(
  4481. open("data/xbox" + str(msg['reply_to_message']['from']['id']) + ".txt", "r").read()).replace(" ",
  4482. "+") + ")\n")
  4483. else:
  4484. XBOX = ""
  4485. if os.path.isfile(
  4486. ("data/steam" + str(msg['reply_to_message']['from']['id']) + ".txt")) == True:
  4487. Steam = str("Steam: [" + str(
  4488. open("data/steam" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4489. "r").read()) + "](http://steamcommunity.com/id/" + str(
  4490. open("data/steam" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4491. "r").read()) + ")\n")
  4492. else:
  4493. Steam = ""
  4494. if os.path.isfile(
  4495. ("data/soundcloud" + str(msg['reply_to_message']['from']['id']) + ".txt")) == True:
  4496. Soundcloud = str("Soundcloud: [" + str(
  4497. open("data/soundcloud" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4498. "r").read()) + "](https://soundcloud.com/" + str(
  4499. open("data/soundcloud" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4500. "r").read()) + ")\n")
  4501. else:
  4502. Soundcloud = ""
  4503. if os.path.isfile(
  4504. ("data/red" + str(msg['reply_to_message']['from']['id']) + ".txt")) == True:
  4505. Reddit = str(
  4506. "Reddit: [" + str(
  4507. open("data/red" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4508. "r").read()) + "](https://www.reddit.com/user/" + str(
  4509. open("data/red" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4510. "r").read()) + ")\n")
  4511. else:
  4512. Reddit = ""
  4513. if os.path.isfile(
  4514. ("data/snapchat" + str(msg['reply_to_message']['from']['id']) + ".txt")) == True:
  4515. Snapchat = str("Snapchat: [" + str(
  4516. open("data/snapchat" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4517. "r").read()) + "](https://www.snapchat.com/add/" + str(
  4518. open("data/snapchat" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4519. "r").read()) + ")\n")
  4520. else:
  4521. Snapchat = ""
  4522. if os.path.isfile(
  4523. ("data/loc" + str(msg['reply_to_message']['from']['id']) + ".txt")) == True:
  4524. Location = str("Location: [" + str(
  4525. open("data/loc" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4526. "r").read()) + "](https://www.google.com/#q=" + str(
  4527. open("data/loc" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4528. "r").read()).replace(" ", "+") + ")\n")
  4529. else:
  4530. Location = ""
  4531. if os.path.isfile(("data/psn" + str(msg['reply_to_message']['from']['id']) + ".txt")) == True:
  4532. PSN = str("PSN: [" + str(open("data/psn" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4533. "r").read()) + "](https://my.playstation.com/" + str(
  4534. open("data/psn" + str(msg['reply_to_message']['from']['id']) + ".txt", "r").read()).replace(" ",
  4535. "+") + ")\n")
  4536. else:
  4537. PSN = ""
  4538. if os.path.isfile(("data/time" + str(msg['reply_to_message']['from']['id']) + ".txt")) == True:
  4539. tf = timezonefinder.TimezoneFinder()
  4540. geo_keys = ['AIzaSyC9CNdTPQGkmm2Wq6e3e-DnC96lNTsdp8s']
  4541. geolocator = geocoders.GoogleV3(api_key=random.choice(geo_keys))
  4542.  
  4543. place, (lat, lng) = geolocator.geocode(
  4544. str(open("data/time" + str(msg['reply_to_message']['from']['id']) + ".txt", 'r').read()))
  4545. timezone_str = tf.certain_timezone_at(lat=lat, lng=lng)
  4546. location = timezone(str(timezone_str))
  4547. location_time = datetime.datetime.now(location)
  4548. userTime = str("Current Time: *" + location_time.strftime('%I:%M %p') + "*\n")
  4549. else:
  4550. userTime = ""
  4551. usermessages = open(str(chat_id) + "/messages/" + str(msg['reply_to_message']['from']['id']) + ".txt",
  4552. "r").read()
  4553. groupmessages = open(str(chat_id) + "/messagecount.txt", "r").read()
  4554. percentage = round((int(usermessages) / int(groupmessages)) * 100, 2)
  4555. print(percentage)
  4556. if message == "/me":
  4557. if "False" in open(str("data/locked" + str(msg['reply_to_message']['from']['id']) + ".txt"), "r"):
  4558. bot.sendMessage(chat_id, "*" + name + " " + star + "*\n\nCoins: *" + str(
  4559. open("rooms/" + str(msg['reply_to_message']['from']['id']) + "money.txt",
  4560. "r").read()) + "\n*Wins: *" + str(
  4561. open("rooms/" + str(msg['reply_to_message']['from']['id']) + "wins.txt",
  4562. "r").read()) + str(mostCoins) + str(mostWins) + str(mostMessages) + "*\n%s%s%s%s%s%s%s%s%s%sYou've sent " % (
  4563. Warns, userTime,
  4564. Instagram, Reddit, Steam, Location, Soundcloud, Snapchat, PSN, XBOX) + open(
  4565. str(chat_id) +
  4566. "/messages/" + str(msg['reply_to_message']['from']['id']) + ".txt", "r").read() + " (" + str(
  4567. percentage) + "%) and this group has " + open(str(chat_id) + "/messagecount.txt",
  4568. "r").read() + " messages.",
  4569. parse_mode="markdown", disable_web_page_preview=True)
  4570. else:
  4571. bot.sendMessage(chat_id, "*" + name + " " + star + "*\n\nThis account is locked! \U0001F512",
  4572. parse_mode="markdown", disable_web_page_preview=True)
  4573. else:
  4574. if str(msg['from']['id']) in OwnerMessage:
  4575. mostMessages = "\nMost Messages Sent \U0001F947"
  4576. else:
  4577. mostMessages = ""
  4578. if str(msg['from']['id']) in OwnerWins:
  4579. mostWins = "\nMost Wins \U0001F947"
  4580. else:
  4581. mostWins = ""
  4582. if str(msg['from']['id']) in OwnerCoins:
  4583. mostCoins = "\nMost Coins \U0001F947"
  4584. else:
  4585. mostCoins = ""
  4586. if str(msg['from']['id']) in open(chat_id + '/data/adminlist.data', 'r').read():
  4587. star = u"\u2B50"
  4588. else:
  4589. if str(messageFromID) in open(str(chat_id) + "/data/admin.txt").read():
  4590. star = u"\u2B50"
  4591. else:
  4592. star = ""
  4593. if os.path.isfile("data/n" + str(messageFromID) + ".txt") == False:
  4594. if " help" in message:
  4595. bot.sendMessage(chat_id,
  4596. "You can add links to your /me message by sending this:\n/me instagram <instagram username>\n/me time <location for time>\n/me reddit <reddit username>\n/me steam <steam username>\n/me location <location>\n/me snapchat <snapchat>\n/me soundcloud <soundcloud>")
  4597. if " instagram " in message:
  4598. if "delete" in msg['text'][14:].lower():
  4599. os.remove("data/insta" + str(messageFromID) + ".txt")
  4600. bot.sendMessage(chat_id, "Instagram removed!")
  4601. else:
  4602. if len(msg['text'][14:].lower()) > 15:
  4603. bot.sendMessage(chat_id, "Not a valid Instagram name.")
  4604. else:
  4605. open("data/insta" + str(messageFromID) + ".txt", "w").write(
  4606. str(msg['text'][14:]))
  4607. bot.sendMessage(chat_id, "Instagram set!")
  4608. if " time " in message:
  4609.  
  4610. if "delete" in msg['text'][9:].lower():
  4611. os.remove("data/time" + str(messageFromID) + ".txt")
  4612. bot.sendMessage(chat_id, "Time removed!")
  4613. else:
  4614. tf = timezonefinder.TimezoneFinder()
  4615. geo_keys = ['AIzaSyC9CNdTPQGkmm2Wq6e3e-DnC96lNTsdp8s']
  4616. geolocator = geocoders.GoogleV3(api_key=random.choice(geo_keys))
  4617. try:
  4618. place, (lat, lng) = geolocator.geocode(
  4619. msg['text'][9:])
  4620. open("data/time" + str(messageFromID) + ".txt", 'w').write(msg['text'][9:])
  4621. timezone_str = tf.certain_timezone_at(lat=lat, lng=lng)
  4622. location = timezone(str(timezone_str))
  4623. location_time = datetime.datetime.now(location)
  4624. userTime = str("Current Time: *" + location_time.strftime('%I:%M %p') + "*\n")
  4625. bot.sendMessage(chat_id, 'Set time!')
  4626. except:
  4627. bot.sendMessage(chat_id, 'Not a valid location!')
  4628. if " psn " in message:
  4629. if "delete" in msg['text'][8:].lower():
  4630. os.remove("data/psn" + str(messageFromID) + ".txt")
  4631. bot.sendMessage(chat_id, "PlayStation removed!")
  4632. else:
  4633. if len(msg['text'][8:].lower()) > 16:
  4634. bot.sendMessage(chat_id, "Not a valid PlayStation name.")
  4635. else:
  4636. open("data/psn" + str(messageFromID) + ".txt",
  4637. "w").write(
  4638. str(msg['text'][8:]))
  4639. bot.sendMessage(chat_id, "PlayStation set!")
  4640. if " xbox " in message:
  4641. if "delete" in msg['text'][9:].lower():
  4642. os.remove("data/xbox" + str(messageFromID) + ".txt")
  4643. bot.sendMessage(chat_id, "Xbox removed!")
  4644. else:
  4645. if len(msg['text'][9].lower()) > 15:
  4646. bot.sendMessage(chat_id, "Not a valid Xbox name.")
  4647. else:
  4648. open("data/xbox" + str(messageFromID) + ".txt",
  4649. "w").write(
  4650. str(msg['text'][9:]))
  4651. bot.sendMessage(chat_id, "Xbox set!")
  4652. if " lock" in message:
  4653. if "True" in open(str("data/locked" + str(messageFromID) + ".txt"), "r"):
  4654. open("data/locked" + str(messageFromID) + ".txt", "w").write("False")
  4655. bot.sendMessage(chat_id,
  4656. "Your /me profile has been unlocked, anyone who replies to your message with /me will be able to see it!")
  4657. else:
  4658. open("data/locked" + str(messageFromID) + ".txt", "w").write("True")
  4659. bot.sendMessage(chat_id,
  4660. "Your /me profile has been locked, anyone who replies to your message with /me will not be able to see it!")
  4661. if " reddit " in message:
  4662. if "delete" in msg['text'][11:].lower():
  4663. os.remove("data/red" + str(messageFromID) + ".txt")
  4664. bot.sendMessage(chat_id, "Reddit removed!")
  4665. else:
  4666. if len(msg['text'][11:].lower()) > 15:
  4667. bot.sendMessage(chat_id, "Not a valid Reddit name.")
  4668. else:
  4669. open("data/red" + str(messageFromID) + ".txt", "w").write(
  4670. str(msg['text'][11:]))
  4671. bot.sendMessage(chat_id, "Reddit set!")
  4672. if " steam " in message:
  4673. if "delete" in msg['text'][10:].lower():
  4674. os.remove("data/steam" + str(messageFromID) + ".txt")
  4675. bot.sendMessage(chat_id, "Steam removed!")
  4676. else:
  4677. if len(msg['text'][10:].lower()) > 20:
  4678. bot.sendMessage(chat_id, "Not a valid Steam name.")
  4679. else:
  4680. open("data/steam" + str(messageFromID) + ".txt", "w").write(
  4681. str(msg['text'][10:]))
  4682. bot.sendMessage(chat_id, "Steam set!")
  4683. if " soundcloud " in message:
  4684. if "delete" in msg['text'][15:].lower():
  4685. os.remove("data/soundcloud" + str(messageFromID) + ".txt")
  4686. bot.sendMessage(chat_id, "Steam removed!")
  4687. else:
  4688. if len(msg['text'][15:].lower()) > 20:
  4689. bot.sendMessage(chat_id, "Not a valid Soundcloud name.")
  4690. else:
  4691. open("data/soundcloud" + str(messageFromID) + ".txt", "w").write(
  4692. str(msg['text'][15:]))
  4693. bot.sendMessage(chat_id, "Soundcloud set!")
  4694. if " snapchat " in message:
  4695. if "delete" in msg['text'][13:].lower():
  4696. os.remove("data/snapchat" + str(messageFromID) + ".txt")
  4697. bot.sendMessage(chat_id, "Snapchat removed!")
  4698. else:
  4699. if len(msg['text'][13:].lower()) > 15:
  4700. bot.sendMessage(chat_id, "Not a valid Snapchat name.")
  4701. else:
  4702. open("data/snapchat" + str(messageFromID) + ".txt", "w").write(
  4703. str(msg['text'][13:]))
  4704. bot.sendMessage(chat_id, "Snapchat set!")
  4705.  
  4706. if os.path.isfile(("data/soundcloud" + str(messageFromID) + ".txt")) == True:
  4707. Soundcloud = str("Soundcloud: [" + str(
  4708. open("data/soundcloud" + str(messageFromID) + ".txt",
  4709. "r").read()) + "](https://soundcloud.com/" + str(
  4710. open("data/soundcloud" + str(messageFromID) + ".txt",
  4711. "r").read()) + ")\n")
  4712. else:
  4713. Soundcloud = ""
  4714. if os.path.isfile(("data/snapchat" + str(messageFromID) + ".txt")) == True:
  4715. Snapchat = str("Snapchat: [" + str(
  4716. open("data/snapchat" + str(messageFromID) + ".txt",
  4717. "r").read()) + "](https://www.snapchat.com/add/" + str(
  4718. open("data/snapchat" + str(messageFromID) + ".txt",
  4719. "r").read()) + ")\n")
  4720. else:
  4721. Snapchat = ""
  4722. if " location " in message:
  4723. if "delete" in msg['text'][13].lower():
  4724. os.remove("data/loc" + str(messageFromID) + ".txt")
  4725. bot.sendMessage(chat_id, "Location removed!")
  4726. else:
  4727. if len(msg['text'][13:].lower()) > 30:
  4728. bot.sendMessage(chat_id, "Not a valid Location name.")
  4729. else:
  4730. open("data/loc" + str(messageFromID) + ".txt", "w").write(
  4731. str(msg['text'][13:]))
  4732. bot.sendMessage(chat_id, "Location set!")
  4733. if os.path.isfile(("data/insta" + str(messageFromID) + ".txt")) == True:
  4734. Instagram = str(
  4735. "Instagram: [" + str(open("data/insta" + str(messageFromID) + ".txt",
  4736. "r").read()) + "](https://www.instagram.com/" + str(
  4737. open("data/insta" + str(messageFromID) + ".txt", "r").read()) + ")\n")
  4738. else:
  4739. Instagram = ""
  4740. if os.path.isfile(("data/steam" + str(messageFromID) + ".txt")) == True:
  4741. Steam = str("Steam: [" + str(open("data/steam" + str(messageFromID) + ".txt",
  4742. "r").read()) + "](http://steamcommunity.com/id/" + str(
  4743. open("data/steam" + str(messageFromID) + ".txt", "r").read()) + ")\n")
  4744. else:
  4745. Steam = ""
  4746. if os.path.isfile(("data/xbox" + str(messageFromID) + ".txt")) == True:
  4747. XBOX = str("Xbox: [" + str(open("data/xbox" + str(messageFromID) + ".txt",
  4748. "r").read()) + "](http://live.xbox.com/en-US/Profile?gamertag=" + str(
  4749. open("data/xbox" + str(messageFromID) + ".txt", "r").read()).replace(" ",
  4750. "+") + ")\n")
  4751. else:
  4752. XBOX = ""
  4753. if os.path.isfile(("data/red" + str(messageFromID) + ".txt")) == True:
  4754. Reddit = str("Reddit: [" + str(open("data/red" + str(messageFromID) + ".txt",
  4755. "r").read()) + "](https://www.reddit.com/user/" + str(
  4756. open("data/red" + str(messageFromID) + ".txt", "r").read()) + ")\n")
  4757. else:
  4758. Reddit = ""
  4759. if os.path.isfile(("data/loc" + str(messageFromID) + ".txt")) == True:
  4760. Location = str("Location: [" + str(open("data/loc" + str(messageFromID) + ".txt",
  4761. "r").read()) + "](https://www.google.com/#q=" + str(
  4762. open("data/loc" + str(messageFromID) + ".txt", "r").read()).replace(" ",
  4763. "+") + ")\n")
  4764. else:
  4765. Location = ""
  4766. if os.path.isfile(("data/psn" + str(messageFromID) + ".txt")) == True:
  4767. PSN = str("PSN: [" + str(open("data/psn" + str(messageFromID) + ".txt",
  4768. "r").read()) + "](https://my.playstation.com/" + str(
  4769. open("data/psn" + str(messageFromID) + ".txt", "r").read()).replace(" ",
  4770. "+") + ")\n")
  4771. else:
  4772. PSN = ""
  4773. if os.path.isfile(str(chat_id) + "/data/" + str(messageFromID) + ".txt") == True:
  4774. Warns = str(
  4775. "Amount of warns: *(" + str(open(str(chat_id) + "/data/" + str(messageFromID) + ".txt",
  4776. "r").read()) + "/3)*\n")
  4777. else:
  4778. Warns = ""
  4779. if os.path.isfile(("data/time" + str(messageFromID) + ".txt")) == True:
  4780. tf = timezonefinder.TimezoneFinder()
  4781. geo_keys = ['AIzaSyC9CNdTPQGkmm2Wq6e3e-DnC96lNTsdp8s']
  4782. geolocator = geocoders.GoogleV3(api_key=random.choice(geo_keys))
  4783.  
  4784. place, (lat, lng) = geolocator.geocode(
  4785. str(open("data/time" + str(messageFromID) + ".txt", 'r').read()))
  4786. timezone_str = tf.certain_timezone_at(lat=lat, lng=lng)
  4787. location = timezone(str(timezone_str))
  4788. location_time = datetime.datetime.now(location)
  4789. userTime = str("Current Time: *" + location_time.strftime('%I:%M %p') + "*\n")
  4790. else:
  4791. userTime = ""
  4792. usermessages = open(str(chat_id) + "/messages/" + str(messageFromID) + ".txt", "r").read()
  4793. groupmessages = open(str(chat_id) + "/messagecount.txt", "r").read()
  4794. percentage = round((int(usermessages) / int(groupmessages)) * 100, 2)
  4795. print(percentage)
  4796. if message == "/me":
  4797. bot.sendMessage(chat_id, "*" + msg['from']['first_name'] + " " + star + "*\n\nCoins: *" + str(
  4798. open("rooms/" + str(messageFromID) + "money.txt",
  4799. "r").read()) + "\n*Wins: *" + str(
  4800. open("rooms/" + str(messageFromID) + "wins.txt",
  4801. "r").read()) + str(mostCoins) + str(mostWins) + str(mostMessages) + "*\n%s%s%s%s%s%s%s%s%s%sYou've sent " % (
  4802. Warns, userTime,
  4803. Instagram, Reddit, Steam, Location, Soundcloud, Snapchat, PSN, XBOX) + open(
  4804. str(chat_id) +
  4805. "/messages/" + str(messageFromID) + ".txt", "r").read() + " (" + str(
  4806. percentage) + "%) and this group has " + open(str(chat_id) + "/messagecount.txt",
  4807. "r").read() + " messages.",
  4808. parse_mode="markdown", disable_web_page_preview=True)
  4809.  
  4810. else:
  4811. if str(msg['from']['id']) in OwnerMessage:
  4812. mostMessages = "\nMost Messages Sent \U0001F947"
  4813. else:
  4814. mostMessages = ""
  4815. if str(msg['from']['id']) in OwnerWins:
  4816. mostWins = "\nMost Wins \U0001F947"
  4817. else:
  4818. mostWins = ""
  4819. if str(msg['from']['id']) in OwnerCoins:
  4820. mostCoins = "\nMost Coins \U0001F947"
  4821. else:
  4822. mostCoins = ""
  4823. if str(messageFromID) in open(chat_id + '/data/adminlist.data', 'r').read():
  4824. star = u"\u2B50"
  4825. else:
  4826. if str(messageFromID) in open(str(chat_id) + "/data/admin.txt").read():
  4827. star = u"\u2B50"
  4828. else:
  4829. star = ""
  4830. if " help" in message:
  4831. bot.sendMessage(chat_id,
  4832. "You can add links to your /me message by sending this:\n/me instagram <instagram username>\n/me time <location for time>\n/me snapchat <snapchat username>\n/me soundcloud <soundcloud username>\n/me reddit <reddit username>\n/me steam <steam username>\n/me location <location>")
  4833.  
  4834. if " instagram " in message:
  4835. if "delete" in msg['text'][14:].lower():
  4836. os.remove("data/insta" + str(messageFromID) + ".txt")
  4837. bot.sendMessage(chat_id, "Instagram removed!")
  4838. else:
  4839. if len(msg['text'][14:].lower()) > 15:
  4840. bot.sendMessage(chat_id, "Not a valid Instagram name.")
  4841. else:
  4842. open("data/insta" + str(messageFromID) + ".txt", "w").write(
  4843. str(msg['text'][14:]))
  4844. bot.sendMessage(chat_id, "Instagram set!")
  4845. if " time " in message:
  4846.  
  4847. if "delete" in msg['text'][9:].lower():
  4848. os.remove("data/time" + str(messageFromID) + ".txt")
  4849. bot.sendMessage(chat_id, "Time removed!")
  4850. else:
  4851. tf = timezonefinder.TimezoneFinder()
  4852. geo_keys = ['AIzaSyC9CNdTPQGkmm2Wq6e3e-DnC96lNTsdp8s']
  4853. geolocator = geocoders.GoogleV3(api_key=random.choice(geo_keys))
  4854. try:
  4855. place, (lat, lng) = geolocator.geocode(
  4856. msg['text'][9:])
  4857. open("data/time" + str(messageFromID) + ".txt", 'w').write(msg['text'][9:])
  4858. timezone_str = tf.certain_timezone_at(lat=lat, lng=lng)
  4859. location = timezone(str(timezone_str))
  4860. location_time = datetime.datetime.now(location)
  4861. userTime = str("Current Time: *" + location_time.strftime('%I:%M %p') + "*\n")
  4862. bot.sendMessage(chat_id, 'Set time!')
  4863. except:
  4864. bot.sendMessage(chat_id, 'Not a valid location!')
  4865. if " psn " in message:
  4866. if "delete" in msg['text'][8:].lower():
  4867. os.remove("data/psn" + str(messageFromID) + ".txt")
  4868. bot.sendMessage(chat_id, "PlayStation removed!")
  4869. else:
  4870. if len(msg['text'][8:].lower()) > 16:
  4871. bot.sendMessage(chat_id, "Not a valid PlayStation name.")
  4872. else:
  4873. open("data/psn" + str(messageFromID) + ".txt",
  4874. "w").write(
  4875. str(msg['text'][8:]))
  4876. bot.sendMessage(chat_id, "PlayStation set!")
  4877. if " xbox " in message:
  4878. if "delete" in msg['text'][9:].lower():
  4879. os.remove("data/xbox" + str(messageFromID) + ".txt")
  4880. bot.sendMessage(chat_id, "Xbox removed!")
  4881. else:
  4882. if len(msg['text'][9].lower()) > 15:
  4883. bot.sendMessage(chat_id, "Not a valid Xbox name.")
  4884. else:
  4885. open("data/xbox" + str(messageFromID) + ".txt",
  4886. "w").write(
  4887. str(msg['text'][9:]))
  4888. bot.sendMessage(chat_id, "Xbox set!")
  4889. if " lock" in message:
  4890. if "True" in open(str("data/locked" + str(messageFromID) + ".txt"), "r"):
  4891. open("data/locked" + str(messageFromID) + ".txt", "w").write("False")
  4892. bot.sendMessage(chat_id,
  4893. "Your /me profile has been unlocked, anyone who replies to your message with /me will be able to see it!")
  4894. else:
  4895. open("data/locked" + str(messageFromID) + ".txt", "w").write("True")
  4896. bot.sendMessage(chat_id,
  4897. "Your /me profile has been locked, anyone who replies to your message with /me will not be able to see it!")
  4898. if " snapchat " in message:
  4899. if "delete" in msg['text'][13:].lower():
  4900. os.remove("data/snapchat" + str(messageFromID) + ".txt")
  4901. bot.sendMessage(chat_id, "Snapchat removed!")
  4902. else:
  4903. if len(msg['text'][13:].lower()) > 15:
  4904. bot.sendMessage(chat_id, "Not a valid Snapchat name.")
  4905. else:
  4906. open("data/snapchat" + str(messageFromID) + ".txt", "w").write(
  4907. str(msg['text'][13:]))
  4908. bot.sendMessage(chat_id, "Snapchat set!")
  4909. if " reddit " in message:
  4910. if "delete" in msg['text'][11:].lower():
  4911. os.remove("data/red" + str(messageFromID) + ".txt")
  4912. bot.sendMessage(chat_id, "Reddit removed!")
  4913. else:
  4914. if len(msg['text'][11:].lower()) > 15:
  4915. bot.sendMessage(chat_id, "Not a valid Reddit name.")
  4916. else:
  4917. open("data/red" + str(messageFromID) + ".txt", "w").write(
  4918. str(msg['text'][11:]))
  4919. bot.sendMessage(chat_id, "Reddit set!")
  4920. if " soundcloud " in message:
  4921. if "delete" in msg['text'][15:].lower():
  4922. os.remove("data/soundcloud" + str(messageFromID) + ".txt")
  4923. bot.sendMessage(chat_id, "Soundcloud removed!")
  4924. else:
  4925. if len(msg['text'][15:].lower()) > 20:
  4926. bot.sendMessage(chat_id, "Not a valid Soundcloud name.")
  4927. else:
  4928. open("data/soundcloud" + str(messageFromID) + ".txt", "w").write(
  4929. str(msg['text'][15:]))
  4930. bot.sendMessage(chat_id, "Soundcloud set!")
  4931. if os.path.isfile(("data/soundcloud" + str(messageFromID) + ".txt")) == True:
  4932. Soundcloud = str("Soundcloud: [" + str(
  4933. open("data/soundcloud" + str(messageFromID) + ".txt",
  4934. "r").read()) + "](https://soundcloud.com/" + str(
  4935. open("data/soundcloud" + str(messageFromID) + ".txt",
  4936. "r").read()) + ")\n")
  4937. else:
  4938. Soundcloud = ""
  4939. if os.path.isfile(("data/snapchat" + str(messageFromID) + ".txt")) == True:
  4940. Snapchat = str("Snapchat: [" + str(
  4941. open("data/snapchat" + str(messageFromID) + ".txt",
  4942. "r").read()) + "](https://www.snapchat.com/add/" + str(
  4943. open("data/snapchat" + str(messageFromID) + ".txt",
  4944. "r").read()) + ")\n")
  4945. else:
  4946. Snapchat = ""
  4947. if " steam " in message:
  4948. if "delete" in msg['text'][10:].lower():
  4949. os.remove("data/steam" + str(messageFromID) + ".txt")
  4950. bot.sendMessage(chat_id, "Steam removed!")
  4951. else:
  4952. if len(msg['text'][10:].lower()) > 20:
  4953. bot.sendMessage(chat_id, "Not a valid Steam name.")
  4954. else:
  4955. open("data/steam" + str(messageFromID) + ".txt", "w").write(
  4956. str(msg['text'][10:]))
  4957. bot.sendMessage(chat_id, "Steam set!")
  4958. if " location " in message:
  4959. if "delete" in msg['text'].lower():
  4960. os.remove("data/loc" + str(messageFromID) + ".txt")
  4961. bot.sendMessage(chat_id, "Location removed!")
  4962. else:
  4963. if len(msg['text'].lower()) > 30:
  4964. bot.sendMessage(chat_id, "Not a valid Location name.")
  4965. else:
  4966. open("data/loc" + str(messageFromID) + ".txt", "w").write(
  4967. str(msg['text'][13:]))
  4968. bot.sendMessage(chat_id, "Location set!")
  4969. if os.path.isfile(("data/insta" + str(messageFromID) + ".txt")) == True:
  4970. Instagram = str(
  4971. "Instagram: [" + str(open("data/insta" + str(messageFromID) + ".txt",
  4972. "r").read()) + "](https://www.instagram.com/" + str(
  4973. open("data/insta" + str(messageFromID) + ".txt", "r").read()) + ")\n")
  4974. else:
  4975. Instagram = ""
  4976. if os.path.isfile(("data/steam" + str(messageFromID) + ".txt")) == True:
  4977. Steam = str("Steam: [" + str(open("data/steam" + str(messageFromID) + ".txt",
  4978. "r").read()) + "](http://steamcommunity.com/id/" + str(
  4979. open("data/steam" + str(messageFromID) + ".txt", "r").read()) + ")\n")
  4980. else:
  4981. Steam = ""
  4982. if os.path.isfile(("data/red" + str(messageFromID) + ".txt")) == True:
  4983. Reddit = str("Reddit: [" + str(open("data/red" + str(messageFromID) + ".txt",
  4984. "r").read()) + "](https://www.reddit.com/user/" + str(
  4985. open("data/red" + str(messageFromID) + ".txt", "r").read()) + ")\n")
  4986. else:
  4987. Reddit = ""
  4988. if os.path.isfile(("data/xbox" + str(messageFromID) + ".txt")) == True:
  4989. XBOX = str("Xbox: [" + str(open("data/xbox" + str(messageFromID) + ".txt",
  4990. "r").read()) + "](http://live.xbox.com/en-US/Profile?gamertag=" + str(
  4991. open("data/xbox" + str(messageFromID) + ".txt", "r").read()).replace(" ",
  4992. "+") + ")\n")
  4993. else:
  4994. XBOX = ""
  4995. if os.path.isfile(("data/loc" + str(messageFromID) + ".txt")) == True:
  4996. Location = str("Location: [" + str(open("data/loc" + str(messageFromID) + ".txt",
  4997. "r").read()) + "](https://www.google.com/#q=" + str(
  4998. open("data/loc" + str(messageFromID) + ".txt", "r").read()).replace(" ",
  4999. "+") + ")\n")
  5000. else:
  5001. Location = ""
  5002. if os.path.isfile(("data/psn" + str(messageFromID) + ".txt")) == True:
  5003. PSN = str("PSN: [" + str(open("data/psn" + str(messageFromID) + ".txt",
  5004. "r").read()) + "](https://my.playstation.com/" + str(
  5005. open("data/psn" + str(messageFromID) + ".txt", "r").read()).replace(" ",
  5006. "+") + ")\n")
  5007. else:
  5008. PSN = ""
  5009. if os.path.isfile(str(chat_id) + "/data/" + str(messageFromID) + ".txt") == True:
  5010. Warns = str(
  5011. "Amount of warns: *(" + str(
  5012. open(str(chat_id) + "/data/" + str(messageFromID) + ".txt", "r").read()) + "/3)*\n")
  5013. else:
  5014. Warns = ""
  5015. if os.path.isfile(("data/time" + str(messageFromID) + ".txt")) == True:
  5016. tf = timezonefinder.TimezoneFinder()
  5017. geo_keys = ['AIzaSyC9CNdTPQGkmm2Wq6e3e-DnC96lNTsdp8s']
  5018. geolocator = geocoders.GoogleV3(api_key=random.choice(geo_keys))
  5019.  
  5020. place, (lat, lng) = geolocator.geocode(
  5021. str(open("data/time" + str(messageFromID) + ".txt", 'r').read()))
  5022. timezone_str = tf.certain_timezone_at(lat=lat, lng=lng)
  5023. location = timezone(str(timezone_str))
  5024. location_time = datetime.datetime.now(location)
  5025. userTime = str("Current Time: *" + location_time.strftime('%I:%M %p') + "*\n")
  5026. else:
  5027. userTime = ""
  5028.  
  5029. usermessages = open(str(chat_id) + "/messages/" + str(messageFromID) + ".txt", "r").read()
  5030. groupmessages = open(str(chat_id) + "/messagecount.txt", "r").read()
  5031. percentage = round((int(usermessages) / int(groupmessages)) * 100, 2)
  5032. print(percentage)
  5033. if message == "/me":
  5034. bot.sendMessage(chat_id, "*" + open(
  5035. "data/n" + str(messageFromID) + ".txt").read() + " " + star + "*\n\nCoins: *" + str(
  5036. open("rooms/" + str(messageFromID) + "money.txt",
  5037. "r").read()) + "\n*Wins: *" + str(
  5038. open("rooms/" + str(messageFromID) + "wins.txt",
  5039. "r").read()) + str(mostCoins) + str(mostWins) + str(mostMessages) + "*\n%s%s%s%s%s%s%s%s%s%sYou've sent " % (
  5040. Warns, userTime,
  5041. Instagram, Reddit, Steam, Location, Soundcloud, Snapchat, PSN, XBOX) + open(str(chat_id) +
  5042. "/messages/" + str(
  5043. messageFromID) + ".txt", "r").read() + " (" + str(
  5044. percentage) + "%) and this group has " + open(str(chat_id) + "/messagecount.txt",
  5045. "r").read() + " messages.",
  5046. parse_mode="markdown", disable_web_page_preview=True)
  5047. else:
  5048. if '@' in msg['text']:
  5049. with open("data/listofusers.data", 'r') as f:
  5050. lines = f.read().split("\n")
  5051.  
  5052. # print("Number of lines is {}".format(len(lines)))
  5053. if '@' in msg['text'][4:]:
  5054. word = str(msg['text'][4:]).replace('@', "").lower()
  5055. else:
  5056. word = str(msg['text'][4:]).lower()
  5057.  
  5058. # iterate over lines, and print out line numbers which contain
  5059. # the word of interest.
  5060. for i, line in enumerate(lines):
  5061. if word in line.lower(): # or word in line.split() to search for full words
  5062. # print("Word \"{}\" found in line {}".format(word, i + 1))
  5063. foundLine = i
  5064. f = open("data/listofusers.data")
  5065. lines = f.readlines()
  5066. meProfileUser = lines[i].split(">:>")[0]
  5067. meProfileName = lines[i].split(">:>")[1].replace('\n', '')
  5068.  
  5069. if " help" in message:
  5070. bot.sendMessage(chat_id,
  5071. "You can add links to your /me message by sending this:\n/me instagram <instagram username>\n/me time <location for time>\n/me reddit <reddit username>\n/me steam <steam username>\n/me location <location>\n/me snapchat <snapchat>\n/me soundcloud <soundcloud>")
  5072. if " instagram " in message:
  5073. if "delete" in msg['text'][14:].lower():
  5074. os.remove("data/insta" + str(meProfileUser) + ".txt")
  5075. bot.sendMessage(chat_id, "Instagram removed!")
  5076. else:
  5077. if len(msg['text'][14:].lower()) > 15:
  5078. bot.sendMessage(chat_id, "Not a valid Instagram name.")
  5079. else:
  5080. open("data/insta" + str(meProfileUser) + ".txt", "w").write(
  5081. str(msg['text'][14:]))
  5082. bot.sendMessage(chat_id, "Instagram set!")
  5083. if " time " in message:
  5084.  
  5085. if "delete" in msg['text'][9:].lower():
  5086. os.remove("data/time" + str(meProfileUser) + ".txt")
  5087. bot.sendMessage(chat_id, "Time removed!")
  5088. else:
  5089. tf = timezonefinder.TimezoneFinder()
  5090. geo_keys = ['AIzaSyC9CNdTPQGkmm2Wq6e3e-DnC96lNTsdp8s']
  5091. geolocator = geocoders.GoogleV3(api_key=random.choice(geo_keys))
  5092. try:
  5093. place, (lat, lng) = geolocator.geocode(
  5094. msg['text'][9:])
  5095. open("data/time" + str(meProfileUser) + ".txt", 'w').write(msg['text'][9:])
  5096. timezone_str = tf.certain_timezone_at(lat=lat, lng=lng)
  5097. location = timezone(str(timezone_str))
  5098. location_time = datetime.datetime.now(location)
  5099. userTime = str("Current Time: *" + location_time.strftime('%I:%M %p') + "*\n")
  5100. bot.sendMessage(chat_id, 'Set time!')
  5101. except:
  5102. bot.sendMessage(chat_id, 'Not a valid location!')
  5103. if " psn " in message:
  5104. if "delete" in msg['text'][8:].lower():
  5105. os.remove("data/psn" + str(meProfileUser) + ".txt")
  5106. bot.sendMessage(chat_id, "PlayStation removed!")
  5107. else:
  5108. if len(msg['text'][8:].lower()) > 16:
  5109. bot.sendMessage(chat_id, "Not a valid PlayStation name.")
  5110. else:
  5111. open("data/psn" + str(meProfileUser) + ".txt",
  5112. "w").write(
  5113. str(msg['text'][8:]))
  5114. bot.sendMessage(chat_id, "PlayStation set!")
  5115. if " xbox " in message:
  5116. if "delete" in msg['text'][9:].lower():
  5117. os.remove("data/xbox" + str(meProfileUser) + ".txt")
  5118. bot.sendMessage(chat_id, "Xbox removed!")
  5119. else:
  5120. if len(msg['text'][9].lower()) > 15:
  5121. bot.sendMessage(chat_id, "Not a valid Xbox name.")
  5122. else:
  5123. open("data/xbox" + str(meProfileUser) + ".txt",
  5124. "w").write(
  5125. str(msg['text'][9:]))
  5126. bot.sendMessage(chat_id, "Xbox set!")
  5127. if " lock" in message:
  5128. if "True" in open(str("data/locked" + str(meProfileUser) + ".txt"), "r"):
  5129. open("data/locked" + str(meProfileUser) + ".txt", "w").write("False")
  5130. bot.sendMessage(chat_id,
  5131. "Your /me profile has been unlocked, anyone who replies to your message with /me will be able to see it!")
  5132. else:
  5133. open("data/locked" + str(meProfileUser) + ".txt", "w").write("True")
  5134. bot.sendMessage(chat_id,
  5135. "Your /me profile has been locked, anyone who replies to your message with /me will not be able to see it!")
  5136. if " reddit " in message:
  5137. if "delete" in msg['text'][11:].lower():
  5138. os.remove("data/red" + str(meProfileUser) + ".txt")
  5139. bot.sendMessage(chat_id, "Reddit removed!")
  5140. else:
  5141. if len(msg['text'][11:].lower()) > 15:
  5142. bot.sendMessage(chat_id, "Not a valid Reddit name.")
  5143. else:
  5144. open("data/red" + str(meProfileUser) + ".txt", "w").write(
  5145. str(msg['text'][11:]))
  5146. bot.sendMessage(chat_id, "Reddit set!")
  5147. if " steam " in message:
  5148. if "delete" in msg['text'][10:].lower():
  5149. os.remove("data/steam" + str(meProfileUser) + ".txt")
  5150. bot.sendMessage(chat_id, "Steam removed!")
  5151. else:
  5152. if len(msg['text'][10:].lower()) > 20:
  5153. bot.sendMessage(chat_id, "Not a valid Steam name.")
  5154. else:
  5155. open("data/steam" + str(meProfileUser) + ".txt", "w").write(
  5156. str(msg['text'][10:]))
  5157. bot.sendMessage(chat_id, "Steam set!")
  5158. if " soundcloud " in message:
  5159. if "delete" in msg['text'][15:].lower():
  5160. os.remove("data/soundcloud" + str(meProfileUser) + ".txt")
  5161. bot.sendMessage(chat_id, "Steam removed!")
  5162. else:
  5163. if len(msg['text'][15:].lower()) > 20:
  5164. bot.sendMessage(chat_id, "Not a valid Soundcloud name.")
  5165. else:
  5166. open("data/soundcloud" + str(meProfileUser) + ".txt", "w").write(
  5167. str(msg['text'][15:]))
  5168. bot.sendMessage(chat_id, "Soundcloud set!")
  5169. if " snapchat " in message:
  5170. if "delete" in msg['text'][13:].lower():
  5171. os.remove("data/snapchat" + str(meProfileUser) + ".txt")
  5172. bot.sendMessage(chat_id, "Snapchat removed!")
  5173. else:
  5174. if len(msg['text'][13:].lower()) > 15:
  5175. bot.sendMessage(chat_id, "Not a valid Snapchat name.")
  5176. else:
  5177. open("data/snapchat" + str(meProfileUser) + ".txt", "w").write(
  5178. str(msg['text'][13:]))
  5179. bot.sendMessage(chat_id, "Snapchat set!")
  5180.  
  5181. if os.path.isfile(("data/soundcloud" + str(meProfileUser) + ".txt")) == True:
  5182. Soundcloud = str("Soundcloud: [" + str(
  5183. open("data/soundcloud" + str(meProfileUser) + ".txt",
  5184. "r").read()) + "](https://soundcloud.com/" + str(
  5185. open("data/soundcloud" + str(meProfileUser) + ".txt",
  5186. "r").read()) + ")\n")
  5187. else:
  5188. Soundcloud = ""
  5189. if os.path.isfile(("data/snapchat" + str(meProfileUser) + ".txt")) == True:
  5190. Snapchat = str("Snapchat: [" + str(
  5191. open("data/snapchat" + str(meProfileUser) + ".txt",
  5192. "r").read()) + "](https://www.snapchat.com/add/" + str(
  5193. open("data/snapchat" + str(meProfileUser) + ".txt",
  5194. "r").read()) + ")\n")
  5195. else:
  5196. Snapchat = ""
  5197. if " location " in message:
  5198. if "delete" in msg['text'][13].lower():
  5199. os.remove("data/loc" + str(meProfileUser) + ".txt")
  5200. bot.sendMessage(chat_id, "Location removed!")
  5201. else:
  5202. if len(msg['text'][13:].lower()) > 30:
  5203. bot.sendMessage(chat_id, "Not a valid Location name.")
  5204. else:
  5205. open("data/loc" + str(meProfileUser) + ".txt", "w").write(
  5206. str(msg['text'][13:]))
  5207. bot.sendMessage(chat_id, "Location set!")
  5208. if os.path.isfile(("data/insta" + str(meProfileUser) + ".txt")) == True:
  5209. Instagram = str(
  5210. "Instagram: [" + str(open("data/insta" + str(meProfileUser) + ".txt",
  5211. "r").read()) + "](https://www.instagram.com/" + str(
  5212. open("data/insta" + str(meProfileUser) + ".txt", "r").read()) + ")\n")
  5213. else:
  5214. Instagram = ""
  5215. if os.path.isfile(("data/steam" + str(meProfileUser) + ".txt")) == True:
  5216. Steam = str("Steam: [" + str(open("data/steam" + str(meProfileUser) + ".txt",
  5217. "r").read()) + "](http://steamcommunity.com/id/" + str(
  5218. open("data/steam" + str(meProfileUser) + ".txt", "r").read()) + ")\n")
  5219. else:
  5220. Steam = ""
  5221. if os.path.isfile(("data/xbox" + str(meProfileUser) + ".txt")) == True:
  5222. XBOX = str("Xbox: [" + str(open("data/xbox" + str(meProfileUser) + ".txt",
  5223. "r").read()) + "](http://live.xbox.com/en-US/Profile?gamertag=" + str(
  5224. open("data/xbox" + str(meProfileUser) + ".txt", "r").read()).replace(" ",
  5225. "+") + ")\n")
  5226. else:
  5227. XBOX = ""
  5228. if os.path.isfile(("data/red" + str(meProfileUser) + ".txt")) == True:
  5229. Reddit = str("Reddit: [" + str(open("data/red" + str(meProfileUser) + ".txt",
  5230. "r").read()) + "](https://www.reddit.com/user/" + str(
  5231. open("data/red" + str(meProfileUser) + ".txt", "r").read()) + ")\n")
  5232. else:
  5233. Reddit = ""
  5234. if os.path.isfile(("data/loc" + str(meProfileUser) + ".txt")) == True:
  5235. Location = str("Location: [" + str(open("data/loc" + str(meProfileUser) + ".txt",
  5236. "r").read()) + "](https://www.google.com/#q=" + str(
  5237. open("data/loc" + str(meProfileUser) + ".txt", "r").read()).replace(" ",
  5238. "+") + ")\n")
  5239. else:
  5240. Location = ""
  5241. if os.path.isfile(("data/psn" + str(meProfileUser) + ".txt")) == True:
  5242. PSN = str("PSN: [" + str(open("data/psn" + str(meProfileUser) + ".txt",
  5243. "r").read()) + "](https://my.playstation.com/" + str(
  5244. open("data/psn" + str(meProfileUser) + ".txt", "r").read()).replace(" ",
  5245. "+") + ")\n")
  5246. else:
  5247. PSN = ""
  5248. if os.path.isfile(str(chat_id) + "/data/" + str(meProfileUser) + ".txt") == True:
  5249. Warns = str(
  5250. "Amount of warns: *(" + str(open(str(chat_id) + "/data/" + str(meProfileUser) + ".txt",
  5251. "r").read()) + "/3)*\n")
  5252. else:
  5253. Warns = ""
  5254. if os.path.isfile(("data/time" + str(meProfileUser) + ".txt")) == True:
  5255. tf = timezonefinder.TimezoneFinder()
  5256. geo_keys = ['AIzaSyC9CNdTPQGkmm2Wq6e3e-DnC96lNTsdp8s']
  5257. geolocator = geocoders.GoogleV3(api_key=random.choice(geo_keys))
  5258.  
  5259. place, (lat, lng) = geolocator.geocode(
  5260. str(open("data/time" + str(meProfileUser) + ".txt", 'r').read()))
  5261. timezone_str = tf.certain_timezone_at(lat=lat, lng=lng)
  5262. location = timezone(str(timezone_str))
  5263. location_time = datetime.datetime.now(location)
  5264. userTime = str("Current Time: *" + location_time.strftime('%I:%M %p') + "*\n")
  5265. else:
  5266. userTime = ""
  5267. if os.path.isfile("data/n" + str(meProfileUser) + ".txt") == True:
  5268. name = open("data/n" + str(meProfileUser) + ".txt").read()
  5269. else:
  5270. name = meProfileName
  5271. print(name)
  5272. if "/me" in msg['text']:
  5273. print('yes')
  5274. bot.sendMessage(chat_id, "*" + name + " " + "*\n\nCoins: *" + str(
  5275. open("rooms/" + str(meProfileUser) + "money.txt",
  5276. "r").read()) + "\n*Wins: *" + str(
  5277. open("rooms/" + str(meProfileUser) + "wins.txt",
  5278. "r").read()) + "*\n%s%s%s%s%s%s%s%s%s%s" % (
  5279. Warns, userTime,
  5280. Instagram, Reddit, Steam, Location, Soundcloud, Snapchat, PSN, XBOX),
  5281. parse_mode="markdown", disable_web_page_preview=True)
  5282. else:
  5283. if os.path.isfile("data/n" + str(messageFromID) + ".txt") == False:
  5284. if " help" in message:
  5285. bot.sendMessage(chat_id,
  5286. "You can add links to your /me message by sending this:\n/me instagram <instagram username>\n/me time <location for time>\n/me reddit <reddit username>\n/me steam <steam username>\n/me location <location>\n/me snapchat <snapchat>\n/me soundcloud <soundcloud>")
  5287. if " instagram " in message:
  5288. if "delete" in msg['text'][14:].lower():
  5289. os.remove("data/insta" + str(messageFromID) + ".txt")
  5290. bot.sendMessage(chat_id, "Instagram removed!")
  5291. else:
  5292. if len(msg['text'][14:].lower()) > 15:
  5293. bot.sendMessage(chat_id, "Not a valid Instagram name.")
  5294. else:
  5295. open("data/insta" + str(messageFromID) + ".txt", "w").write(
  5296. str(msg['text'][14:]))
  5297. bot.sendMessage(chat_id, "Instagram set!")
  5298. if " time " in message:
  5299.  
  5300. if "delete" in msg['text'][9:].lower():
  5301. os.remove("data/time" + str(messageFromID) + ".txt")
  5302. bot.sendMessage(chat_id, "Time removed!")
  5303. else:
  5304. tf = timezonefinder.TimezoneFinder()
  5305. geo_keys = ['AIzaSyC9CNdTPQGkmm2Wq6e3e-DnC96lNTsdp8s']
  5306. geolocator = geocoders.GoogleV3(api_key=random.choice(geo_keys))
  5307. try:
  5308. place, (lat, lng) = geolocator.geocode(
  5309. msg['text'][9:])
  5310. open("data/time" + str(messageFromID) + ".txt", 'w').write(msg['text'][9:])
  5311. timezone_str = tf.certain_timezone_at(lat=lat, lng=lng)
  5312. location = timezone(str(timezone_str))
  5313. location_time = datetime.datetime.now(location)
  5314. userTime = str("Current Time: *" + location_time.strftime('%I:%M %p') + "*\n")
  5315. bot.sendMessage(chat_id, 'Set time!')
  5316. except:
  5317. bot.sendMessage(chat_id, 'Not a valid location!')
  5318. if " psn " in message:
  5319. if "delete" in msg['text'][8:].lower():
  5320. os.remove("data/psn" + str(messageFromID) + ".txt")
  5321. bot.sendMessage(chat_id, "PlayStation removed!")
  5322. else:
  5323. if len(msg['text'][8:].lower()) > 16:
  5324. bot.sendMessage(chat_id, "Not a valid PlayStation name.")
  5325. else:
  5326. open("data/psn" + str(messageFromID) + ".txt",
  5327. "w").write(
  5328. str(msg['text'][8:]))
  5329. bot.sendMessage(chat_id, "PlayStation set!")
  5330. if " xbox " in message:
  5331. if "delete" in msg['text'][9:].lower():
  5332. os.remove("data/xbox" + str(messageFromID) + ".txt")
  5333. bot.sendMessage(chat_id, "Xbox removed!")
  5334. else:
  5335. if len(msg['text'][9].lower()) > 15:
  5336. bot.sendMessage(chat_id, "Not a valid Xbox name.")
  5337. else:
  5338. open("data/xbox" + str(messageFromID) + ".txt",
  5339. "w").write(
  5340. str(msg['text'][9:]))
  5341. bot.sendMessage(chat_id, "Xbox set!")
  5342. if " reddit " in message:
  5343. if "delete" in msg['text'][11:].lower():
  5344. os.remove("data/red" + str(messageFromID) + ".txt")
  5345. bot.sendMessage(chat_id, "Reddit removed!")
  5346. else:
  5347. if len(msg['text'][11:].lower()) > 15:
  5348. bot.sendMessage(chat_id, "Not a valid Reddit name.")
  5349. else:
  5350. open("data/red" + str(messageFromID) + ".txt", "w").write(
  5351. str(msg['text'][11:]))
  5352. bot.sendMessage(chat_id, "Reddit set!")
  5353. if " lock" in message:
  5354. if "True" in open(str("data/locked" + str(messageFromID) + ".txt"), "r"):
  5355. open("data/locked" + str(messageFromID) + ".txt", "w").write("False")
  5356. bot.sendMessage(chat_id,
  5357. "Your /me profile has been unlocked, anyone who replies to your message with /me will be able to see it!")
  5358. else:
  5359. open(str("data/locked" + str(messageFromID) + ".txt")).write("True")
  5360. open("data/locked" + str(messageFromID) + ".txt", "w").write("True")
  5361. bot.sendMessage(chat_id,
  5362. "Your /me profile has been locked, anyone who replies to your message with /me will not be able to see it!")
  5363. if " steam " in message:
  5364. if "delete" in msg['text'][10:].lower():
  5365. os.remove("data/steam" + str(messageFromID) + ".txt")
  5366. bot.sendMessage(chat_id, "Steam removed!")
  5367. else:
  5368. if len(msg['text'][10:].lower()) > 20:
  5369. bot.sendMessage(chat_id, "Not a valid Steam name.")
  5370. else:
  5371. open("data/steam" + str(messageFromID) + ".txt", "w").write(
  5372. str(msg['text'][10:]))
  5373. bot.sendMessage(chat_id, "Steam set!")
  5374. if " soundcloud " in message:
  5375. if "delete" in msg['text'][15:].lower():
  5376. os.remove("data/soundcloud" + str(messageFromID) + ".txt")
  5377. bot.sendMessage(chat_id, "Soundcloud removed!")
  5378. else:
  5379. if len(msg['text'][15:].lower()) > 20:
  5380. bot.sendMessage(chat_id, "Not a valid Soundcloud name.")
  5381. else:
  5382. open("data/soundcloud" + str(messageFromID) + ".txt", "w").write(
  5383. str(msg['text'][15:]))
  5384. bot.sendMessage(chat_id, "Soundcloud set!")
  5385. if " snapchat " in message:
  5386. if "delete" in msg['text'][13:].lower():
  5387. os.remove("data/snapchat" + str(messageFromID) + ".txt")
  5388. bot.sendMessage(chat_id, "Snapchat removed!")
  5389. else:
  5390. if len(msg['text'][13:].lower()) > 15:
  5391. bot.sendMessage(chat_id, "Not a valid Snapchat name.")
  5392. else:
  5393. open("data/snapchat" + str(messageFromID) + ".txt", "w").write(
  5394. str(msg['text'][13:]))
  5395. bot.sendMessage(chat_id, "Snapchat set!")
  5396.  
  5397. if os.path.isfile(("data/soundcloud" + str(messageFromID) + ".txt")) == True:
  5398. Soundcloud = str("Soundcloud: [" + str(
  5399. open("data/soundcloud" + str(messageFromID) + ".txt",
  5400. "r").read()) + "](https://soundcloud.com/" + str(
  5401. open("data/soundcloud" + str(messageFromID) + ".txt",
  5402. "r").read()) + ")\n")
  5403. else:
  5404. Soundcloud = ""
  5405. if os.path.isfile(("data/snapchat" + str(messageFromID) + ".txt")) == True:
  5406. Snapchat = str("Snapchat: [" + str(
  5407. open("data/snapchat" + str(messageFromID) + ".txt",
  5408. "r").read()) + "](https://www.snapchat.com/add/" + str(
  5409. open("data/snapchat" + str(messageFromID) + ".txt",
  5410. "r").read()) + ")\n")
  5411. else:
  5412. Snapchat = ""
  5413. if " location " in message:
  5414. if "delete" in msg['text'][13:].lower():
  5415. os.remove("data/loc" + str(messageFromID) + ".txt")
  5416. bot.sendMessage(chat_id, "Location removed!")
  5417. else:
  5418. if len(msg['text'][13:].lower()) > 30:
  5419. bot.sendMessage(chat_id, "Not a valid Location name.")
  5420. else:
  5421. open("data/loc" + str(messageFromID) + ".txt", "w").write(
  5422. str(msg['text'][13:]))
  5423. bot.sendMessage(chat_id, "Location set!")
  5424. if os.path.isfile(("data/insta" + str(messageFromID) + ".txt")) == True:
  5425. Instagram = str(
  5426. "Instagram: [" + str(open("data/insta" + str(messageFromID) + ".txt",
  5427. "r").read()) + "](https://www.instagram.com/" + str(
  5428. open("data/insta" + str(messageFromID) + ".txt", "r").read()) + ")\n")
  5429. else:
  5430. Instagram = ""
  5431. if os.path.isfile(("data/steam" + str(messageFromID) + ".txt")) == True:
  5432. Steam = str("Steam: [" + str(open("data/steam" + str(messageFromID) + ".txt",
  5433. "r").read()) + "](http://steamcommunity.com/id/" + str(
  5434. open("data/steam" + str(messageFromID) + ".txt", "r").read()) + ")\n")
  5435. else:
  5436. Steam = ""
  5437. if os.path.isfile(("data/red" + str(messageFromID) + ".txt")) == True:
  5438. Reddit = str("Reddit: [" + str(open("data/red" + str(messageFromID) + ".txt",
  5439. "r").read()) + "](https://www.reddit.com/user/" + str(
  5440. open("data/red" + str(messageFromID) + ".txt", "r").read()) + ")\n")
  5441. else:
  5442. Reddit = ""
  5443. if os.path.isfile(("data/xbox" + str(messageFromID) + ".txt")) == True:
  5444. XBOX = str("Xbox: [" + str(open("data/xbox" + str(messageFromID) + ".txt",
  5445. "r").read()) + "](http://live.xbox.com/en-US/Profile?gamertag=" + str(
  5446. open("data/xbox" + str(messageFromID) + ".txt", "r").read()).replace(" ",
  5447. "+") + ")\n")
  5448. else:
  5449. XBOX = ""
  5450. if os.path.isfile(("data/loc" + str(messageFromID) + ".txt")) == True:
  5451. Location = str("Location: [" + str(open("data/loc" + str(messageFromID) + ".txt",
  5452. "r").read()) + "](https://www.google.com/#q=" + str(
  5453. open("data/loc" + str(messageFromID) + ".txt", "r").read()).replace(" ",
  5454. "+") + ")\n")
  5455. else:
  5456. Location = ""
  5457. if os.path.isfile(("data/psn" + str(messageFromID) + ".txt")) == True:
  5458. PSN = str("PSN: [" + str(open("data/psn" + str(messageFromID) + ".txt",
  5459. "r").read()) + "](https://my.playstation.com/" + str(
  5460. open("data/psn" + str(messageFromID) + ".txt", "r").read()).replace(" ",
  5461. "+") + ")\n")
  5462. else:
  5463. PSN = ""
  5464. if os.path.isfile(str(chat_id) + "/data/" + str(messageFromID) + ".txt") == True:
  5465. Warns = str(
  5466. "Amount of warns: *(" + str(open(str(chat_id) + "/data/" + str(messageFromID) + ".txt",
  5467. "r").read()) + "/3)*\n")
  5468. else:
  5469. Warns = ""
  5470. if os.path.isfile(("data/time" + str(messageFromID) + ".txt")) == True:
  5471. tf = timezonefinder.TimezoneFinder()
  5472. geo_keys = ['AIzaSyC9CNdTPQGkmm2Wq6e3e-DnC96lNTsdp8s']
  5473. geolocator = geocoders.GoogleV3(api_key=random.choice(geo_keys))
  5474.  
  5475. place, (lat, lng) = geolocator.geocode(str(open("data/time" + str(messageFromID) + ".txt", 'r').read()))
  5476. timezone_str = tf.certain_timezone_at(lat=lat, lng=lng)
  5477. location = timezone(str(timezone_str))
  5478. location_time = datetime.datetime.now(location)
  5479. userTime = str("Current Time: *" + location_time.strftime('%I:%M %p') + "*\n")
  5480. else:
  5481. userTime = ""
  5482. if message == "/me":
  5483. bot.sendMessage(chat_id, "*" + msg['from']['first_name'] + " " + star + "*\n\nCoins: *" + str(
  5484. open("rooms/" + str(messageFromID) + "money.txt",
  5485. "r").read()) + "\n*Wins: *" + str(
  5486. open("rooms/" + str(messageFromID) + "wins.txt",
  5487. "r").read()) + "*\n%s%s%s%s%s%s%s%s%s%s" % (
  5488. Warns, userTime,
  5489. Instagram, Reddit, Steam, Location, Soundcloud, Snapchat, PSN, XBOX), parse_mode="markdown", disable_web_page_preview=True)
  5490.  
  5491. else:
  5492. star = ""
  5493. if " help" in message:
  5494. bot.sendMessage(chat_id,
  5495. "You can add links to your /me message by sending this:\n/me instagram <instagram username>\n/me time <location for time>\n/me snapchat <snapchat username>\n/me soundcloud <soundcloud username>\n/me reddit <reddit username>\n/me steam <steam username>\n/me location <location>")
  5496.  
  5497. if " instagram " in message:
  5498. if "delete" in msg['text'][14:].lower():
  5499. os.remove("data/insta" + str(messageFromID) + ".txt")
  5500. bot.sendMessage(chat_id, "Instagram removed!")
  5501. else:
  5502. if len(msg['text'][14:].lower()) > 15:
  5503. bot.sendMessage(chat_id, "Not a valid Instagram name.")
  5504. else:
  5505. open("data/insta" + str(messageFromID) + ".txt", "w").write(
  5506. str(msg['text'][14:]))
  5507. bot.sendMessage(chat_id, "Instagram set!")
  5508. if " time " in message:
  5509.  
  5510. if "delete" in msg['text'][9:].lower():
  5511. os.remove("data/time" + str(messageFromID) + ".txt")
  5512. bot.sendMessage(chat_id, "Time removed!")
  5513. else:
  5514. tf = timezonefinder.TimezoneFinder()
  5515. geo_keys = ['AIzaSyC9CNdTPQGkmm2Wq6e3e-DnC96lNTsdp8s']
  5516. geolocator = geocoders.GoogleV3(api_key=random.choice(geo_keys))
  5517. try:
  5518. place, (lat, lng) = geolocator.geocode(
  5519. msg['text'][9:])
  5520. open("data/time" + str(messageFromID) + ".txt", 'w').write(msg['text'][9:])
  5521. timezone_str = tf.certain_timezone_at(lat=lat, lng=lng)
  5522. location = timezone(str(timezone_str))
  5523. location_time = datetime.datetime.now(location)
  5524. userTime = str("Current Time: *" + location_time.strftime('%I:%M %p') + "*\n")
  5525. bot.sendMessage(chat_id, 'Set time!')
  5526. except:
  5527. bot.sendMessage(chat_id, 'Not a valid location!')
  5528. if " psn " in message:
  5529. if "delete" in msg['text'][8:].lower():
  5530. os.remove("data/psn" + str(messageFromID) + ".txt")
  5531. bot.sendMessage(chat_id, "PlayStation removed!")
  5532. else:
  5533. if len(msg['text'][8:].lower()) > 16:
  5534. bot.sendMessage(chat_id, "Not a valid PlayStation name.")
  5535. else:
  5536. open("data/psn" + str(messageFromID) + ".txt",
  5537. "w").write(
  5538. str(msg['text'][8:]))
  5539. bot.sendMessage(chat_id, "PlayStation set!")
  5540. if " xbox " in message:
  5541. if "delete" in msg['text'][9:].lower():
  5542. os.remove("data/xbox" + str(messageFromID) + ".txt")
  5543. bot.sendMessage(chat_id, "Xbox removed!")
  5544. else:
  5545. if len(msg['text'][9].lower()) > 15:
  5546. bot.sendMessage(chat_id, "Not a valid Xbox name.")
  5547. else:
  5548. open("data/xbox" + str(messageFromID) + ".txt",
  5549. "w").write(
  5550. str(msg['text'][9:]))
  5551. bot.sendMessage(chat_id, "Xbox set!")
  5552. if " lock" in message:
  5553. if "True" in open(str("data/locked" + str(messageFromID) + ".txt"), "r"):
  5554. open("data/locked" + str(messageFromID) + ".txt", "w").write("False")
  5555. bot.sendMessage(chat_id,
  5556. "Your /me profile has been unlocked, anyone who replies to your message with /me will be able to see it!")
  5557. else:
  5558. open(str("data/locked" + str(messageFromID) + ".txt")).write("True")
  5559. open("data/locked" + str(messageFromID) + ".txt", "w").write("True")
  5560. bot.sendMessage(chat_id,
  5561. "Your /me profile has been locked, anyone who replies to your message with /me will not be able to see it!")
  5562. if " snapchat " in message:
  5563. if "delete" in msg['text'][13:].lower():
  5564. os.remove("data/snapchat" + str(messageFromID) + ".txt")
  5565. bot.sendMessage(chat_id, "Snapchat removed!")
  5566. else:
  5567. if len(msg['text'][13:].lower()) > 15:
  5568. bot.sendMessage(chat_id, "Not a valid Snapchat name.")
  5569. else:
  5570. open("data/snapchat" + str(messageFromID) + ".txt", "w").write(
  5571. str(msg['text'][13:]))
  5572. bot.sendMessage(chat_id, "Snapchat set!")
  5573. if " reddit " in message:
  5574. if "delete" in msg['text'][11:].lower():
  5575. os.remove("data/red" + str(messageFromID) + ".txt")
  5576. bot.sendMessage(chat_id, "Reddit removed!")
  5577. else:
  5578. if len(msg['text'][11:].lower()) > 15:
  5579. bot.sendMessage(chat_id, "Not a valid Reddit name.")
  5580. else:
  5581. open("data/red" + str(messageFromID) + ".txt", "w").write(
  5582. str(msg['text'][11:]))
  5583. bot.sendMessage(chat_id, "Reddit set!")
  5584. if " soundcloud " in message:
  5585. if "delete" in msg['text'][15:].lower():
  5586. os.remove("data/soundcloud" + str(messageFromID) + ".txt")
  5587. bot.sendMessage(chat_id, "Steam removed!")
  5588. else:
  5589. if len(msg['text'][15:].lower()) > 20:
  5590. bot.sendMessage(chat_id, "Not a valid Soundcloud name.")
  5591. else:
  5592. open("data/soundcloud" + str(messageFromID) + ".txt", "w").write(
  5593. str(msg['text'][15:]))
  5594. bot.sendMessage(chat_id, "Soundcloud set!")
  5595. if os.path.isfile(("data/soundcloud" + str(messageFromID) + ".txt")) == True:
  5596. Soundcloud = str("Soundcloud: [" + str(
  5597. open("data/soundcloud" + str(messageFromID) + ".txt",
  5598. "r").read()) + "](https://soundcloud.com/" + str(
  5599. open("data/soundcloud" + str(messageFromID) + ".txt",
  5600. "r").read()) + ")\n")
  5601. else:
  5602. Soundcloud = ""
  5603. if os.path.isfile(("data/snapchat" + str(messageFromID) + ".txt")) == True:
  5604. Snapchat = str("Snapchat: [" + str(
  5605. open("data/snapchat" + str(messageFromID) + ".txt",
  5606. "r").read()) + "](https://www.snapchat.com/add/" + str(
  5607. open("data/snapchat" + str(messageFromID) + ".txt",
  5608. "r").read()) + ")\n")
  5609. else:
  5610. Snapchat = ""
  5611. if " steam " in message:
  5612. if "delete" in msg['text'][10:].lower():
  5613. os.remove("data/steam" + str(messageFromID) + ".txt")
  5614. bot.sendMessage(chat_id, "Steam removed!")
  5615. else:
  5616. if len(msg['text'][10:].lower()) > 20:
  5617. bot.sendMessage(chat_id, "Not a valid Steam name.")
  5618. else:
  5619. open("data/steam" + str(messageFromID) + ".txt", "w").write(
  5620. str(msg['text'][10:]))
  5621. bot.sendMessage(chat_id, "Steam set!")
  5622. if " location " in message:
  5623. if "delete" in msg['text'].lower():
  5624. os.remove("data/loc" + str(messageFromID) + ".txt")
  5625. bot.sendMessage(chat_id, "Location removed!")
  5626. else:
  5627. if len(msg['text'].lower()) > 30:
  5628. bot.sendMessage(chat_id, "Not a valid Location name.")
  5629. else:
  5630. open("data/loc" + str(messageFromID) + ".txt", "w").write(
  5631. str(msg['text'][13:]))
  5632. bot.sendMessage(chat_id, "Location set!")
  5633. if os.path.isfile(("data/insta" + str(messageFromID) + ".txt")) == True:
  5634. Instagram = str(
  5635. "Instagram: [" + str(open("data/insta" + str(messageFromID) + ".txt",
  5636. "r").read()) + "](https://www.instagram.com/" + str(
  5637. open("data/insta" + str(messageFromID) + ".txt", "r").read()) + ")\n")
  5638. else:
  5639. Instagram = ""
  5640. if os.path.isfile(("data/steam" + str(messageFromID) + ".txt")) == True:
  5641. Steam = str("Steam: [" + str(open("data/steam" + str(messageFromID) + ".txt",
  5642. "r").read()) + "](http://steamcommunity.com/id/" + str(
  5643. open("data/steam" + str(messageFromID) + ".txt", "r").read()) + ")\n")
  5644. else:
  5645. Steam = ""
  5646. if os.path.isfile(("data/red" + str(messageFromID) + ".txt")) == True:
  5647. Reddit = str("Reddit: [" + str(open("data/red" + str(messageFromID) + ".txt",
  5648. "r").read()) + "](https://www.reddit.com/user/" + str(
  5649. open("data/red" + str(messageFromID) + ".txt", "r").read()) + ")\n")
  5650. else:
  5651. Reddit = ""
  5652. if os.path.isfile(("data/loc" + str(messageFromID) + ".txt")) == True:
  5653. Location = str("Location: [" + str(open("data/loc" + str(messageFromID) + ".txt",
  5654. "r").read()) + "](https://www.google.com/#q=" + str(
  5655. open("data/loc" + str(messageFromID) + ".txt", "r").read()).replace(" ",
  5656. "+") + ")\n")
  5657. else:
  5658. Location = ""
  5659. if os.path.isfile(("data/psn" + str(messageFromID) + ".txt")) == True:
  5660. PSN = str("PSN: [" + str(open("data/psn" + str(messageFromID) + ".txt",
  5661. "r").read()) + "](https://my.playstation.com/" + str(
  5662. open("data/psn" + str(messageFromID) + ".txt", "r").read()).replace(" ",
  5663. "+") + ")\n")
  5664. else:
  5665. PSN = ""
  5666. if os.path.isfile(("data/xbox" + str(messageFromID) + ".txt")) == True:
  5667. XBOX = str("Xbox: [" + str(open("data/xbox" + str(messageFromID) + ".txt",
  5668. "r").read()) + "](http://live.xbox.com/en-US/Profile?gamertag=" + str(
  5669. open("data/xbox" + str(messageFromID) + ".txt", "r").read()).replace(" ",
  5670. "+") + ")\n")
  5671. else:
  5672. XBOX = ""
  5673.  
  5674. if os.path.isfile(("data/time" + str(messageFromID) + ".txt")) == True:
  5675. tf = timezonefinder.TimezoneFinder()
  5676. geo_keys = ['AIzaSyC9CNdTPQGkmm2Wq6e3e-DnC96lNTsdp8s']
  5677. geolocator = geocoders.GoogleV3(api_key=random.choice(geo_keys))
  5678.  
  5679. place, (lat, lng) = geolocator.geocode(str(open("data/time" + str(messageFromID) + ".txt", 'r').read()))
  5680. timezone_str = tf.certain_timezone_at(lat=lat, lng=lng)
  5681. location = timezone(str(timezone_str))
  5682. location_time = datetime.datetime.now(location)
  5683. userTime = str("Current Time: *" + location_time.strftime('%I:%M %p') + "*\n")
  5684. else:
  5685. userTime = ""
  5686.  
  5687.  
  5688. if os.path.isfile(str(chat_id) + "/data/" + str(messageFromID) + ".txt") == True:
  5689. Warns = str(
  5690. "Amount of warns: *(" + str(
  5691. open(str(chat_id) + "/data/" + str(messageFromID) + ".txt", "r").read()) + "/3)*\n")
  5692. else:
  5693. Warns = ""
  5694. if message == "/me":
  5695. bot.sendMessage(chat_id, "*" + open(
  5696. "data/n" + str(messageFromID) + ".txt").read() + " " + star + "*\n\nCoins: *" + str(
  5697. open("rooms/" + str(messageFromID) + "money.txt",
  5698. "r").read()) + "\n*Wins: *" + str(
  5699. open("rooms/" + str(messageFromID) + "wins.txt",
  5700. "r").read()) + "*\n%s%s%s%s%s%s%s%s%s%s" % (
  5701. Warns, userTime,
  5702. Instagram, Reddit, Steam, Location, Soundcloud, Snapchat, PSN, XBOX),
  5703. parse_mode="markdown", disable_web_page_preview=True)
  5704.  
  5705.  
  5706. if "hi bot" in message:
  5707. bot.sendMessage(chat_id, "Hi, " + usersName + "!")
  5708. if messageType == "private":
  5709. if "/start" in message:
  5710. bot.sendMessage(chat_id, "Hello, " + usersName + ". I am Imma Bot, and I am a multi-purpose chat bot! For updates, follow @ImmaBotDev. To see my commands, use /commands. To send feedback, use '/feedback <message>'")
  5711. if "/help" in message:
  5712. bot.sendMessage(chat_id, "Commands:\n/roll and /roll2\n/read\n/detect\n/listen\n/saturate\n/solarize\n/posterize\n/swirl\n/polaroid\n/rblur\n/caption and /captionb for black text\n/kickme\n/def\n/jokes\n/callme\n/addcom and /delcom (add custom commands)\n/blur\n/contour\n/me\n/equalize\n/sharpen\n/invert\n/equalize\n\nAdmin Commands:\n/limit (for games)\n/promote and /demote\n/ban and /unban\n/kick\n/mute and /unmute\n/byebot (Makes the bot leave the group)\n/photo\n/wel (Toggles welcome message)\n/eb (Toggles 8ball)\n/jt (Toggles jokes)\n/rt (Toggles rolling)\n/gt (Toggles games)\n/reset (Removes warns)\n/end (Ends current game)\n/toggles (Shows whats on and off, some are fillers)\n/antibot doesn't allow bots into the group\n/lock locks the group\n/nomedia restricts any media messages(reply to user)")
  5713. def sticker():
  5714. if 'reply_to_message' in msg:
  5715. try:
  5716. Bot.send_chat_action(chat_id, action=telegram.ChatAction.TYPING)
  5717. file_id = msg['reply_to_message']['photo'][-1]['file_id']
  5718. filename = str(msg['reply_to_message']['from']['id']) + ".png"
  5719. bot.download_file(file_id, filename)
  5720. im = Image.open(filename)
  5721. im.thumbnail((512, 512))
  5722. im.save("1" + filename)
  5723. bot.sendDocument(chat_id, open("1" + filename, "rb"))
  5724. os.remove(filename)
  5725. os.remove("1" + filename)
  5726. except:
  5727. bot.sendMessage(chat_id, "Error occured")
  5728. else:
  5729. bot.sendMessage(chat_id, "Reply to a photo.")
  5730. if "/stick" in message:
  5731. if stickerExecute == True:
  5732. t = threading.Thread(target=sticker)
  5733. t.start()
  5734. else:
  5735. stickerExecute = True
  5736. if "/forget" in message:
  5737. if os.path.isfile("data/n" + str(messageFromID) + ".txt") == True:
  5738. bot.sendMessage(chat_id, "_Your name has been forgotten_", parse_mode="markdown")
  5739. os.remove("data/n" + str(messageFromID) + ".txt")
  5740. if messageType != 'private':
  5741. if "True" in open(str(chat_id) + "/data/8ball.txt", "r"):
  5742. if "/magic8 " in message:
  5743. if str(msg['text'][8:]).startswith('will'):
  5744. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5745. reply_to_message_id=msg['message_id'])
  5746. elif str(msg['text'][8:]).startswith('can'):
  5747. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5748. reply_to_message_id=msg['message_id'])
  5749. elif str(msg['text'][8:]).startswith('is'):
  5750. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5751. reply_to_message_id=msg['message_id'])
  5752. elif str(msg['text'][8:]).startswith('are'):
  5753. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5754. reply_to_message_id=msg['message_id'])
  5755. elif str(msg['text'][8:]).startswith('does'):
  5756. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5757. reply_to_message_id=msg['message_id'])
  5758. elif str(msg['text'][8:]).startswith('has'):
  5759. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5760. reply_to_message_id=msg['message_id'])
  5761. else:
  5762. bot.sendMessage(chat_id, (random.choice(eightball)),
  5763. reply_to_message_id=msg['message_id'])
  5764. if message == "/magic8":
  5765. bot.sendMessage(chat_id, '/magic8 <question>')
  5766. if message == '/m8':
  5767. bot.sendMessage(chat_id, "/m8 <question>")
  5768. if message == '/m8@ImmaChatBot':
  5769. bot.sendMessage(chat_id, "/m8 <question>")
  5770. if message.startswith("/m8 "):
  5771. if str(msg['text'][4:]).startswith('will'):
  5772. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5773. reply_to_message_id=msg['message_id'])
  5774. elif str(msg['text'][4:]).startswith('can'):
  5775. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5776. reply_to_message_id=msg['message_id'])
  5777. elif str(msg['text'][4:]).startswith('r '):
  5778. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5779. reply_to_message_id=msg['message_id'])
  5780. elif str(msg['text'][4:]).startswith('should'):
  5781. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5782. reply_to_message_id=msg['message_id'])
  5783. elif str(msg['text'][4:]).startswith('would'):
  5784. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5785. reply_to_message_id=msg['message_id'])
  5786. elif str(msg['text'][4:]).startswith('is'):
  5787. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5788. reply_to_message_id=msg['message_id'])
  5789. elif str(msg['text'][4:]).startswith('how big'):
  5790. bot.sendMessage(chat_id, "I don't know, I haven't seen how big it is.")
  5791. elif str(msg['text'][4:]).startswith('how long'):
  5792. bot.sendMessage(chat_id, "I don't know, I haven't seen how long it is.")
  5793. elif str(msg['text'][4:]).startswith('are'):
  5794. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5795. reply_to_message_id=msg['message_id'])
  5796. elif str(msg['text'][4:]).startswith('does'):
  5797. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5798. reply_to_message_id=msg['message_id'])
  5799. elif str(msg['text'][4:]).startswith('did'):
  5800. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5801. reply_to_message_id=msg['message_id'])
  5802. elif str(msg['text'][4:]).startswith('am'):
  5803. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5804. reply_to_message_id=msg['message_id'])
  5805. elif str(msg['text'][4:]).startswith('kiss'):
  5806. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5807. reply_to_message_id=msg['message_id'])
  5808. elif str(msg['text'][4:]).startswith('has'):
  5809. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5810. reply_to_message_id=msg['message_id'])
  5811. elif str(msg['text'][4:]).startswith('when'):
  5812. bot.sendMessage(chat_id, (random.choice(smartball)),
  5813. reply_to_message_id=msg['message_id'])
  5814. elif str(msg['text'][4:]).startswith('what tim'):
  5815. bot.sendMessage(chat_id, (random.choice(smartball)),
  5816. reply_to_message_id=msg['message_id'])
  5817. elif str(msg['text'][4:]) == 'right':
  5818. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5819. reply_to_message_id=msg['message_id'])
  5820. elif str(msg['text'][4:]) == 'right?':
  5821. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5822. reply_to_message_id=msg['message_id'])
  5823. elif "don't you" in str(msg['text'][4:]):
  5824. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5825. reply_to_message_id=msg['message_id'])
  5826. elif "dont you" in str(msg['text'][4:]):
  5827. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5828. reply_to_message_id=msg['message_id'])
  5829. else:
  5830. bot.sendMessage(chat_id, (random.choice(eightball)),
  5831. reply_to_message_id=msg['message_id'])
  5832. if message.startswith("/8ball "):
  5833. if str(msg['text'][7:]).startswith('will'):
  5834. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5835. reply_to_message_id=msg['message_id'])
  5836. elif str(msg['text'][7:]).startswith('can'):
  5837. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5838. reply_to_message_id=msg['message_id'])
  5839. elif str(msg['text'][7:]).startswith('r '):
  5840. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5841. reply_to_message_id=msg['message_id'])
  5842. elif str(msg['text'][7:]).startswith('should'):
  5843. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5844. reply_to_message_id=msg['message_id'])
  5845. elif str(msg['text'][7:]).startswith('would'):
  5846. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5847. reply_to_message_id=msg['message_id'])
  5848. elif str(msg['text'][7:]).startswith('is'):
  5849. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5850. reply_to_message_id=msg['message_id'])
  5851. elif str(msg['text'][7:]).startswith('how big'):
  5852. bot.sendMessage(chat_id, "I don't know, I haven't seen how big it is.")
  5853. elif str(msg['text'][7:]).startswith('how long'):
  5854. bot.sendMessage(chat_id, "I don't know, I haven't seen how long it is.")
  5855. elif str(msg['text'][7:]).startswith('are'):
  5856. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5857. reply_to_message_id=msg['message_id'])
  5858. elif str(msg['text'][7:]).startswith('does'):
  5859. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5860. reply_to_message_id=msg['message_id'])
  5861. elif str(msg['text'][7:]).startswith('did'):
  5862. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5863. reply_to_message_id=msg['message_id'])
  5864. elif str(msg['text'][7:]).startswith('am'):
  5865. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5866. reply_to_message_id=msg['message_id'])
  5867. elif str(msg['text'][7:]).startswith('kiss'):
  5868. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5869. reply_to_message_id=msg['message_id'])
  5870. elif str(msg['text'][7:]).startswith('has'):
  5871. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5872. reply_to_message_id=msg['message_id'])
  5873. elif str(msg['text'][7:]).startswith('when'):
  5874. bot.sendMessage(chat_id, (random.choice(smartball)),
  5875. reply_to_message_id=msg['message_id'])
  5876. elif str(msg['text'][7:]).startswith('what tim'):
  5877. bot.sendMessage(chat_id, (random.choice(smartball)),
  5878. reply_to_message_id=msg['message_id'])
  5879. elif str(msg['text'][7:]) == 'right':
  5880. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5881. reply_to_message_id=msg['message_id'])
  5882. elif str(msg['text'][7:]) == 'right?':
  5883. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5884. reply_to_message_id=msg['message_id'])
  5885. elif "don't you" in str(msg['text'][7:]):
  5886. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5887. reply_to_message_id=msg['message_id'])
  5888. elif "dont you" in str(msg['text'][7:]):
  5889. bot.sendMessage(chat_id, (random.choice(easyeightball)),
  5890. reply_to_message_id=msg['message_id'])
  5891. else:
  5892. bot.sendMessage(chat_id, (random.choice(eightball)),
  5893. reply_to_message_id=msg['message_id'])
  5894. def on_callback_query(msg):
  5895. query_id, from_id, query_data = telepot.glance(msg, flavor='callback_query')
  5896. if query_data == 'create_':
  5897. keyboard = InlineKeyboardMarkup(
  5898. inline_keyboard=[[InlineKeyboardButton(text="Cancel", callback_data='cancel_')]])
  5899. bot.editMessageText(edited, "Alright, what would you like your username to be? (5-18 characters)", reply_markup=keyboard)
  5900. open(str(msg['from']['id']) + "login.txt", "w").write("createusername")
  5901. open(str(msg['from']['id']) + "data.txt", "w").write(str(msg['from']['id']))
  5902. elif query_data == 'cancel_':
  5903. os.remove(str(from_id) + "login.txt")
  5904. bot.editMessageText(edited, "All operations have been canceled.")
  5905. elif query_data == 'changepassword_':
  5906. keyboard = InlineKeyboardMarkup(
  5907. inline_keyboard=[[InlineKeyboardButton(text="Back", callback_data='Back_')]])
  5908. open(str(msg['from']['id']) + "login.txt", "w").write("changepassword")
  5909. bot.editMessageText(edited, "Enter your old password:", reply_markup=keyboard)
  5910. elif query_data == 'logout_':
  5911. if os.path.isfile('login/' + str(
  5912. open('login/' + str(from_id) + 'LOGGED.txt').read()) + 'AUTH.txt'):
  5913. if str(from_id) in open('login/' + str(
  5914. open("login/" + str(from_id) + "LOGGED.txt", 'r').read()) + 'AUTH.txt').read():
  5915. bot.editMessageText(edited, "You have logged out of " + str(open("login/" + str(
  5916. from_id) + "LOGGED.txt").read()) + '. 2-Auth has been deactivated.')
  5917. if '1' in open('login/' + str(
  5918. open("login/" + str(from_id) + "LOGGED.txt", 'r').read()) + 'AMOUNT.txt').read():
  5919. os.remove(
  5920. 'login/' + str(open("login/" + str(from_id) + "LOGGED.txt", 'r').read()) + 'AMOUNT.txt')
  5921. os.remove("login/" + str(open("login/" + str(from_id) + "LOGGED.txt").read()) + "AUTH.txt")
  5922. os.remove("login/" + str(from_id) + "LOGGED.txt")
  5923. else:
  5924. aadd = int(str(open('login/' + str(
  5925. open("login/" + str(from_id) + "LOGGED.txt", 'r').read()) + 'AMOUNT.txt').read())) - 1
  5926. open('login/' + str(open("login/" + str(from_id) + "LOGGED.txt", 'r').read()) + 'AMOUNT.txt',
  5927. 'w').write(str(aadd))
  5928. else:
  5929. if '1' in open('login/' + str(open("login/" + str(from_id) + "LOGGED.txt",
  5930. 'r').read()) + 'AMOUNT.txt').read():
  5931. os.remove('login/' + str(open("login/" + str(from_id) + "LOGGED.txt",
  5932. 'r').read()) + 'AMOUNT.txt')
  5933. else:
  5934. aadd = int(str(open('login/' + str(
  5935. open("login/" + str(from_id) + "LOGGED.txt",
  5936. 'r').read()) + 'AMOUNT.txt').read())) - 1
  5937. open('login/' + str(open("login/" + str(from_id) + "LOGGED.txt",
  5938. 'r').read()) + 'AMOUNT.txt', 'w').write(str(aadd))
  5939. bot.editMessageText(edited, "You have logged out of " + str(
  5940. open("login/" + str(from_id) + "LOGGED.txt").read()) + '.')
  5941. os.remove("login/" + str(from_id) + "LOGGED.txt")
  5942. else:
  5943. bot.editMessageText(edited, "You have logged out of " + str(
  5944. open("login/" + str(from_id) + "LOGGED.txt").read()) + '.')
  5945. if '1' in open('login/' + str(
  5946. open("login/" + str(from_id) + "LOGGED.txt", 'r').read()) + 'AMOUNT.txt').read():
  5947. os.remove('login/' + str(open("login/" + str(from_id) + "LOGGED.txt", 'r').read()) + 'AMOUNT.txt')
  5948. os.remove("login/" + str(from_id) + "LOGGED.txt")
  5949. else:
  5950. aadd = int(str(open('login/' + str(
  5951. open("login/" + str(from_id) + "LOGGED.txt", 'r').read()) + 'AMOUNT.txt').read())) - 1
  5952. open('login/' + str(open("login/" + str(from_id) + "LOGGED.txt", 'r').read()) + 'AMOUNT.txt',
  5953. 'w').write(str(aadd))
  5954. else:
  5955. bot.editMessageText(edited, "please..",
  5956. parse_mode="markdown")
  5957. print(str(open("token.dat", "r").read()))
  5958.  
  5959. with open(os.path.dirname(os.path.realpath(__file__)) + '/token.dat') as file:
  5960. TOKEN = file.readline().strip()
  5961.  
  5962. bot = telepot.Bot(TOKEN)
  5963. Bot = telegram.Bot(TOKEN)
  5964. #bot.message_loop(handle)
  5965. bot.message_loop(handle)
  5966. while 1:
  5967. time.sleep(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement