def send_captcha(self, group_jid, peer_jid): # TODO clear self.bot_info if verification is off. Also clear self.message_sent in both cases: veri on and off. time_ = Database("data.db").get_join_time(group_jid) join_time = 1 if time_ is None else time_ seconds_since_join = time.time() - join_time verification_status = Database("data.db").get_verification_status( group_jid) verification_time = Database('data.db').get_verification_time( group_jid) if (seconds_since_join > 43200 or join_time is 1) and verification_status != "off": self.client.send_chat_message( group_jid, "Type the characters in the image to prove that you are not a bot." "\nYOU WILL BE REMOVED IF YOU DO NOT SOLVE IT.") ans = self.cap.captcha() self.client.send_chat_image(group_jid, 'captcha1.jpg') self.peer_eval.append((peer_jid, group_jid, ans)) self.verified[peer_jid] = False verify_thread = Timer(verification_time, self.captcha_removal_check, args=(group_jid, peer_jid, ans)) verify_thread.start() else: if verification_status != "off": seconds_left = 43200 - seconds_since_join hours_left = seconds_left // 3600 minutes_left = (seconds_left - hours_left * 3600) // 60 self.client.send_chat_message( group_jid, "I am unable to send captchas for another : " "{} hours and {} minutes".format(hours_left, minutes_left))
def on_group_status_received(self, response: chatting.IncomingGroupStatus): print("[+] Status message in {}: {}".format(response.group_jid, response.status)) if 'invited' not in response.status and 'has joined the chat' in response.status: self.veri_queue.append([response.group_jid, response.status_jid]) print(colorama.Fore.RED + str(self.veri_queue)) Thread(target=self.bot_detect, args=()).start() if 'has joined the chat' in response.status: if len(response.group.admins) == 1: self.owner.append( response.group.owner[0] ) # to differentiate between database update and bot verify in peer response print("######self.owner########", self.owner) if Database('data.db').check_existence(response.group_jid) is True: self.databaseUpdate.admin_update(response.group_jid, response.group.owner, response.group.admins) else: self.databaseUpdate.added_first_time(response.group_jid, response.group.owner, response.group.admins) if 'invited' in response.status: welcome_msg = Database('data.db').get_welcome_msg( response.group_jid) if welcome_msg is not None: self.client.send_chat_message(response.group_jid, welcome_msg)
def setup_database(): db = Database() db.create() user_controller = UserController() user_controller.sign_user(username=SU_NAME, email=None, password=SU_PASS, superuser=True) text_controller = TextController() text_controller.add_text('So I\'m two inches away from her. \ Her luscious lips part. \ Just as I\'m about to kiss her, she looks at me and she says, \ "What\'s your name?" Gogol Ganguli. End of seduction 101.') text_controller.add_text('Speed test text to complete') text_controller.add_text('Another speed test for you!') tutorial_controller = TutorialController() tutorial_controller.add_tutorial('aa ss dd ff jj kk ll ;;') tutorial_controller.add_tutorial('as as df df jk jk l; l;') tutorial_controller.add_tutorial('asdf asdf jkl; jkl;') tutorial_controller.add_tutorial('fdsa fdsa ;lkj ;lkj') tutorial_controller.add_tutorial('jkl; jkl; asdf asdf') tutorial_controller.add_tutorial(';lkj ;lkj fdsa fdsa') tutorial_controller.add_tutorial('ee ii ee ii') tutorial_controller.add_tutorial('ei ei ie ie') tutorial_controller.add_tutorial('fefe fefe efef efef')
def send_captcha(self, group_jid, peer_jid): # TODO clear self.bot_info if verification is off. Also clear self.message_sent in both cases: veri on and off. time_ = Database("data.db").get_join_time(group_jid) join_time = 1 if time_ is None else time_ verification_status = Database("data.db").get_verification_status( group_jid) verification_time = Database('data.db').get_verification_time( group_jid) if (time.time() - join_time > 43200 or join_time is 1) and verification_status != "off": self.client.send_chat_message( group_jid, "Type the characters in the image to prove that you are not a bot." "\nYOU WILL BE REMOVED IF YOU DO NOT SOLVE IT.") ans = self.cap.captcha() self.client.send_chat_image(group_jid, 'captcha1.jpg') self.peer_eval.append((peer_jid, group_jid, ans)) self.verified[peer_jid] = False verify_thread = Timer(verification_time, self.captcha_removal_check, args=(group_jid, peer_jid, ans)) verify_thread.start()
def on_group_sysmsg_received(self, response: chatting.IncomingGroupSysmsg): print("[+] System message in {}: {}".format(response.group_jid, response.sysmsg)) if 'added you' in response.sysmsg: if Database('data.db').check_existence( response.group_jid) is False: self.databaseUpdate.added_first_time(response.group_jid, response.group.owner, response.group.admins) else: Database('data.db').update_join_time(response.group_jid, time.time()) elif 'removed from the group' in response.sysmsg: self.databaseUpdate.delete_group_info(response.group_jid)
def set_verification_time(self, new_time, group_jid, peer_jid): message = Database("data.db").update_verification_time( new_time, group_jid, peer_jid) self.client.send_chat_message( group_jid, "Verification time set to {} minutes".format( new_time // 60) if message is 1 else "Nice try Rage" if message is 2 else "Verification time can only be set by an admin")
def set_verification_days(self, new_days, group_jid, peer_jid): message = Database("data.db").update_verification_days( new_days, group_jid, peer_jid) self.client.send_chat_message( group_jid, "Verification days set to {}".format(new_days) if message is 1 else "Nice try Rage" if message is 2 else "Verification days can only be set by an admin")
def welcome_message(self, welcome_msg, group_jid, peer_jid): message = Database('data.db').update_welcome_msg( welcome_msg, group_jid, peer_jid) self.client.send_chat_message( group_jid, "welcome message set to:\n {}".format(welcome_msg) if message == 1 else "Nice try Rage" if message == 2 else "welcome message can only be set by an admin")
def setup_database(): db = Database() db.create() # db.insert() controller = UserController() controller.sign_user(username=SU_NAME, email=None, password=SU_PASS, superuser=True) controller = MovieController() controller.add_movie('The Hunger Games: Catching Fire', 7.9) controller.add_movie('Wreck-It Ralph', 7.8) controller.add_movie('Her', 8.3) controller = ProjectionController() controller.add_projection(1, '3D', '2020-04-01', '19:10') controller.add_projection(1, '2D', '2020-04-01', '19:00') controller.add_projection(1, '4DX', '2020-04-02', '21:00') controller.add_projection(3, '2D', '2020-04-05', '20:20') controller.add_projection(2, '3D', '2020-04-02', '22:00') controller.add_projection(2, '2D', '2020-04-02', '19:30')
def broadcast(self, message, lin): jid = Database("data.db").get_all_groups() for j in jid: print(colorama.Fore.BLUE + "BROADCASTING") try: self.client.send_chat_message(j + "@groups.kik.com", message) self.client.send_link(j + "@groups.kik.com", link=lin, title="Survey") if lin is not None else None rt = random.randrange(5, 10) time.sleep(rt) except(): print(colorama.Fore.BLUE + "not found")
def captcha_response_eval(self, peer_jid, group_jid, ans, response): if str(ans) in response.lower().replace(' ', ''): welcome_msg = Database('data.db').get_welcome_msg(group_jid) self.client.send_chat_message(group_jid, 'Welcome!') if welcome_msg is not None: self.client.send_chat_message(group_jid, welcome_msg) self.verified[peer_jid] = True elif not self.verified[peer_jid]: self.client.send_chat_message(group_jid, 'Wrong, try again')
def update(self, users): print(type(users)) # a = [ast.literal_eval(e) for e in users] admins = {k: v for k, v, x in users} print(set(admins.keys())) print(self.buffer) for buffer in self.buffer: if set(buffer[3]) == set(admins.keys()): if buffer[0] == 'admin_update': print(buffer) Database("data.db").update_admins(buffer[1], str(buffer[2]), str(admins)) self.check_own_owner(users, buffer) elif buffer[0] == 'group_init': Database("data.db").group_init(buffer[1], time.time(), "on", "on", str(buffer[2]), str(admins), 180, None, 20) self.buffer.remove(buffer)
class Migration: def __init__(self): self.database = Database("data.db") def file_read(self): self.database.create_table("group_info(group_jid TEXT NOT NULL, join_time REAL, wiki_status TEXT, " "verification_status TEXT, owner TEXT, admins TEXT, PRIMARY KEY(group_jid))") directory = os.fsencode("/home/wolfie/kik-bot-api-unofficial/examples") for file in os.listdir(directory): filename = os.fsdecode(file) if filename.endswith(".dat") and filename.startswith("11"): self.database.migrate_data(filename.split('_')[0] + "_" + filename.split('_')[1], None, "on", "on", None, None) self.database.cursor.close() self.database.connection.close() # if os.path.isfile(filename.split('.')[0]) or os.path.isfile(filename.split('.')[0] + '.dir'): # with shelve.open(filename, writeback=True) as f: # if variable_name in f.keys(): # print('1') # return f[variable_name] # else: # return None def name_migration(self): self.database.create_table() directory = os.fsencode("/home/wolfie/Downloads/15jun/home/anmol/kik-bot-api-unofficial/examples") for file in os.listdir(directory): filename = os.fsdecode(file) if filename.endswith("_data") and filename.startswith("11"): print(filename) # if os.path.isfile(filename.split('.')[0]) or os.path.isfile(filename.split('.')[0] + '.dir'): with shelve.open("/home/wolfie/Downloads/15jun/home/anmol/kik-bot-api-unofficial/examples/" + filename) as f: print((list(f.keys()))) if "name_dict" in f.keys(): print('1') names = f["name_dict"] else: names = {} print(names) # self.database.name_migration(filename.split('_')[0] + "_" + filename.split('_')[1], names) self.database.cursor.close() self.database.connection.close() def drop_table(self): self.database.drop_table()
def set_verification_status(self, status, group_jid, peer_jid): message = Database("data.db").update_verification_status( status, group_jid, peer_jid) if status == 'off': self.client.send_chat_message( group_jid, "Verification turned off" if message is 1 else "Verification can only be turned off by an admin" if message is 2 else "Verification is already off" if message is 3 else "Nice try Rage") else: self.client.send_chat_message( group_jid, "Verification turned on" if message is 1 else "Verification can only be turned on by an admin" if message is 2 else "Verification is already on" if message is 3 else "Nice try Rage")
def set_wiki_status(self, status, group_jid, peer_jid): message = Database("data.db").update_wiki_status( status, group_jid, peer_jid) if status == 'off' or status == 'temp': self.client.send_chat_message( group_jid, "Nerd mode turned off" if message is 1 else "Nerd mode can only be turned off by an admin" if message is 2 else "Nerd mode is already off" if message is 3 else "Nice try Rage" if message is 4 else "Nerd mode turned off for 60 minutes" if message is 5 else "Nerd mode is already off") else: self.client.send_chat_message( group_jid, "Nerd mode turned on" if message is 1 else "Nerd mode can only be turned on by an admin" if message is 2 else "Nerd mode is already on" if message is 3 else "Nice try Rage" if message is 4 else "Nerd mode turned on" if message is 5 else "Nerd mode is already on") if status == 'temp': status_thread = Timer(3600, self.status_timer, args=(group_jid, peer_jid)) status_thread.start()
def delete_group_info(self, group_jid): Database('data.db').delete_row(group_jid)
def on_group_message_received(self, chat_message: chatting.IncomingGroupChatMessage): s = chat_message.body.lower() # -------------------------- # Captcha Eval # ------------------------- # TODO optimize it, no need to create an evaluation thread for every single message sent. (although no # performance issues noticed) self.verify.eval_message(chat_message.from_jid, chat_message.group_jid, chat_message.body) # -------------------------- # Verification status # ------------------------- if s == "eve stop verification": # admin print(1) VerifyStatus(self.client).set_verification_status("off", chat_message.group_jid, chat_message.from_jid) elif s == "eve start verification": # admin print(2) VerifyStatus(self.client).set_verification_status("on", chat_message.group_jid, chat_message.from_jid) elif "eve set verification time to" in s: # admin try: ti = int(s.split("eve set verification time to ")[1]) * 60 VerifyStatus(self.client).set_verification_time(ti, chat_message.group_jid, chat_message.from_jid) except Exception: self.client.send_chat_message(chat_message.group_jid, "give only a number after command\n" "example: eve set verification time to 5") elif "eve set verification days to" in s: # admin try: d = int(s.split("eve set verification days to ")[1]) VerifyStatus(self.client).set_verification_days(d, chat_message.group_jid, chat_message.from_jid) except Exception: self.client.send_chat_message(chat_message.group_jid, "give only a number after command\n" "example: eve set verification days to 5") elif s == "eve verification time left": # user t = Database('data.db').get_join_time(chat_message.group_jid) if time.time() - t > 43200: self.client.send_chat_message(chat_message.group_jid, "I can verify now") else: time_left = 43200 - (time.time() - t) hours = time_left // 3600 minutes = (time_left - hours * 3600) // 60 self.client.send_chat_message(chat_message.group_jid, "Captcha verification will start after : " "{} hours and {} minutes".format(hours, minutes)) elif "eve set welcome message to " in s: # admin welcome_msg = chat_message.body.split("Eve set welcome message to ")[1] DatabaseUpdate(self.client).welcome_message(welcome_msg, chat_message.group_jid, chat_message.from_jid) # -------------------------- # Wiki status # ------------------------- elif s == "eve stop forever": # admin WikiStatus(self.client).set_wiki_status('off', chat_message.group_jid, chat_message.from_jid) elif s == "eve start": WikiStatus(self.client).set_wiki_status('on', chat_message.group_jid, chat_message.from_jid) elif s == "eve stop": WikiStatus(self.client).set_wiki_status('temp', chat_message.group_jid, chat_message.from_jid) # -------------------------- # given name # ------------------------- elif "eve call me" in s: name = chat_message.body.split('Eve call me ')[1] self.client.send_chat_message(chat_message.group_jid, "Ok, {}".format(name)) Database("data.db").given_name(name, chat_message.group_jid, chat_message.from_jid) elif "eve forget my name" in s: # TODO this does not work :( Database("data.db").delete_given_name(chat_message.group_jid, chat_message.from_jid) elif s == 'hey' or s == 'hey eve': name = Database("data.db").get_given_name(chat_message.group_jid, chat_message.from_jid) name = '' if name is None else name self.client.send_chat_message(chat_message.group_jid, "Hello {}".format(name)) # ------------------------- # misc # ------------------------- elif s == 'eve leave': # admin admins = ast.literal_eval(Database("data.db").get_admins(chat_message.group_jid)) print(admins) for key in admins.keys(): print(key) if key == chat_message.from_jid and admins[key] != 'Rage bot': self.databaseUpdate.delete_group_info(chat_message.group_jid) self.client.leave_group(chat_message.group_jid) break # if admins[key] == 'Rage bot': # self.client.send_chat_message(chat_message.group_jid, "I ain't leaving Rage") # break elif s == 'eve': self.client.send_chat_message(chat_message.group_jid, 'Hello I\'m Eve. You called?') elif 'eve' in s and 'hug' in s: reply = np.random.choice([0, 1, 2, 3]) if reply == 0: self.client.send_chat_message(chat_message.group_jid, 'sure pay me 10 shmekles first') self.client.send_chat_message(chat_message.group_jid, 'nah, I\'m just kidding.\n' 'I give hugs for free. *hugs*') elif reply == 1: self.client.send_chat_message(chat_message.group_jid, 'sure! *hugs*') elif reply == 2: self.client.send_chat_message(chat_message.group_jid, 'One hug coming right up') self.client.send_chat_message(chat_message.group_jid, '*big hug* 😀') else: self.client.send_chat_message(chat_message.group_jid, '*hugs* 😊') elif s == 'eve toss a coin': print(14) outcome = random.choice([0, 1]) self.client.send_chat_message(chat_message.group_jid, 'It\'s a head' if outcome == 1 else 'It\'s a tail') elif 'eve' in s and ' or ' in s and len(s) < 100: print(15) yo = re.findall('\\b' + 'eve' + '\\b', chat_message.body, flags=re.IGNORECASE) if yo != []: tokens = nltk.word_tokenize(s) for i in range(len(tokens)): if tokens[i] == 'or': out1 = str(tokens[i - 1]) out2 = str(tokens[i + 1]) if out1 == 'me': out1 = 'you' if out2 == 'me': out2 = 'you' outcome = random.choice([0, 1]) self.client.send_chat_message(chat_message.group_jid, out1 if outcome == 1 else out2) elif s == 'eve who is your dad' or s == 'eve who made you': print(16) self.client.send_chat_message(chat_message.group_jid, 'I was created by Wolfie.\nYou can contact him at: @suckawolf') # -------------------------- # movies # ------------------------- elif "movies" in s and "eve " in s: print(7) mv = Movies().fetch_movies(s, chat_message.group_jid) self.client.send_chat_message(chat_message.group_jid, f'you can watch:\n{mv[0]}\n{mv[1]}\n{mv[2]}\n{mv[3]}\n{mv[4]}') elif "movie" in s and "eve " in s: print(8) mv = Movies().fetch_movies(s, chat_message.group_jid) self.client.send_chat_message(chat_message.group_jid, f'I hear {mv[0]} is a good {"" if mv[1] is "web series" else mv[1]} movie') # -------------------------- # Wiki answers # ------------------------- elif "eve what is" in s or "eve who is" in s or "eve where is" in s or "eve what are" in s \ or "eve who are" in s or "eve where are" in s or "eve what's" in s: t = Thread(target=self.wiki_manual, args=(chat_message.group_jid, chat_message.body)) t.start() # else: # Wiki(self.client).wiki_thread_starter(chat_message.group_jid, chat_message.body) # -------------------------- # Substitutions # ------------------------- elif " > " in chat_message.body: sub = chat_message.body.split(" > ") group = self.mongo.find_by_jid(chat_message.group_jid) self.dialogues.save_dialogue(sub, group, chat_message.group_jid) elif " >> " in chat_message.body: sub = chat_message.body.split(" >> ") admins = ast.literal_eval(Database("data.db").get_admins(chat_message.group_jid)) admins = list(admins.keys()) if chat_message.from_jid in admins: group = self.mongo.find_by_jid(chat_message.group_jid) self.dialogues.save_admin_dialogue(sub, group, chat_message.group_jid) else: self.client.send_chat_message(chat_message.group_jid, "This can only be done by an admin") elif " >>> " in chat_message.body: sub = chat_message.body.split(" >>> ") group = self.mongo.find_by_jid(chat_message.group_jid) self.dialogues.save_user_dialogue(sub, group, chat_message.group_jid, chat_message.from_jid) elif "eve delete" in s: key = s.split["eve delete "][0] substitution = self.mongo.find_by_jid(chat_message.group_jid).substitutions.filter(key=key, user_jid=chat_message.from_jid) print(chat_message.from_jid) if len(substitution) != 0: print("123") substitution.delete() else: substitution = self.mongo.find_by_jid(chat_message.group_jid).substitutions.filter( key=chat_message.body, user_jid=None) if len(substitution) != 0: self.client.send_chat_message(chat_message.group_jid, substitution[0].value) else: substitution = self.mongo.find_by_jid(chat_message.group_jid).substitutions.filter(key=chat_message.body, user_jid=chat_message.from_jid) print(chat_message.from_jid) if len(substitution) != 0: print("123") self.client.send_chat_message(chat_message.group_jid, substitution[0].value) else: substitution = self.mongo.find_by_jid(chat_message.group_jid).substitutions.filter( key=chat_message.body, user_jid=None) if len(substitution) != 0: self.client.send_chat_message(chat_message.group_jid, substitution[0].value)
def status_timer(self, group_jid, peer_jid): Database('data.db').update_wiki_status('on', group_jid, peer_jid) self.client.send_chat_message(group_jid, 'On again')
def auto_remove(self): """ score = 40 if self.bot_auto['days'] < 0.01 else score = 30 if self.bot_auto['days'] < 0.1 else score = 25 if self.bot_auto['days'] < 0.5 else score = 20 if self.bot_auto['days'] < 1.0 else score = 15 if self.bot_auto['days'] < 5 else score = 10 """ if self.bot_auto['days'] < 0.01: score = 40 elif self.bot_auto['days'] < 0.1: score = 30 elif self.bot_auto['days'] < 0.5: score = 25 elif self.bot_auto['days'] < 1.0: score = 20 elif self.bot_auto['days'] < 5.0: score = 15 else: score = 10 both_name = self.bot_auto['screen_name'].split(' ') if len(both_name) == 2: score += 5 with open('data/bot_names.pickle', 'rb') as f: bot_names = pickle.load(f) first_name = bot_names['first_name'] last_name = bot_names['last_name'] if both_name[0] in first_name and both_name[1] in last_name: score += 25 if both_name[0] in self.bot_auto['user_name']: score += 20 if len([ char for char in self.bot_auto['user_name'] if char.isdigit() ]) > 2: score += 20 if score >= 80: # self.client.send_chat_message(self.bot_auto['group_jid'], 'bot detected: ' + str(score)) self.client.remove_peer_from_group(self.bot_auto['group_jid'], self.bot_auto['peer_jid']) else: # self.client.send_chat_message(self.bot_auto['group_jid'], 'not bot' + str(score)) try: if self.bot_auto['days'] <= Database( 'data.db').get_verification_days( self.bot_auto['group_jid']): self.send_captcha(self.bot_auto['group_jid'], self.bot_auto['peer_jid']) else: welcome_msg = Database('data.db').get_welcome_msg( self.bot_auto['group_jid']) if welcome_msg is not None: self.client.send_chat_message( self.bot_auto['group_jid'], welcome_msg) except: welcome_msg = Database('data.db').get_welcome_msg( self.bot_auto['group_jid']) if welcome_msg is not None: self.client.send_chat_message( self.bot_auto['group_jid'], welcome_msg) # Database('data.db').bot_init(self.bot_auto) # for e in self.bot_info: # if e == self.bot_auto: # self.bot_info.remove(e) # break self.bot_auto = {}
def wiki_thread_starter(self, group_jid, message): status = Database("data.db").get_wiki_status(group_jid) if status == 'on': t = Thread(target=self.wiki_threader, args=(message, group_jid)) t.daemon = True t.start()
def __init__(self): self.database = Database("data.db")