def run(self): response_text = None if len(self.user_params) == 0: response_text = "@" + self.author.first_name + " Please enter something. Anything." else: try: if len(self.user_params) == 1: response_text = "@" + self.author.first_name + " Your lucky number is {}"\ .format(random.randint(1, int(self.user_params[0]))) elif len(self.user_params) == 2 and int( self.user_params[1]) > int(self.user_params[0]): response_text = "@" + self.author.first_name + " Your lucky number is {}"\ .format(random.randint(int(self.user_params[0]), int(self.user_params[1]))) except: pass if response_text is None: response_text = "@" + self.author.first_name + " Your lucky item is " + random.choice( self.user_params) mentions = [ Mention(self.author_id, length=len(self.author.first_name) + 1) ] self.client.send(Message(text=response_text, mentions=mentions), thread_id=self.thread_id, thread_type=self.thread_type)
def run(self): mentions = [ Mention(self.author_id, length=len(self.author.first_name) + 1) ] response_text = "@" + self.author.first_name + " Here is your link: \n" steal = events() if len(self.user_params) != 0: try: url = steal.shorten_url(self.user_params[0]) response_text += url except: try: url = steal.shorten_url("http://" + self.user_params[0]) response_text += url except: response_text = "@" + self.author.first_name + " Could not find link to shorten" elif self.message_object.replied_to != None: try: url = steal.shorten_url(self.message_object.replied_to.text) response_text += url except: try: url = steal.shorten_url( "http://" + self.message_object.replied_to.text) response_text += url except: response_text = "@" + self.author.first_name + " Could not find link to shorten" else: response_text = "@" + self.author.first_name + " Could not find link to shorten" self.client.send(Message(text=response_text, mentions=mentions), thread_id=self.thread_id, thread_type=self.thread_type)
def run(self): mentions = [Mention(self.author_id, length=len(self.author.first_name) + 1)] if len(self.user_params) == 0: response_text = "@" + self.author.first_name + " Here you go." + "\n" + "https://en.wikipedia.org/wiki/Nothing" else: try: link = "https://en.wikipedia.org/w/index.php?search="+"_".join(self.user_params) webpage = requests.get(link) text = str(bs4.BeautifulSoup(webpage.text, 'html.parser').find("div", class_="mw-search-result-heading")) if text == "None": link = webpage.url else: text = text[text.find("href") + 6:] text = text[:text.find("\"")] link = "https://en.wikipedia.org" + text response_text = "@" + self.author.first_name + " Here's what I found for you about " + " ".join(self.user_params) \ + "\n" + link except: response_text = "@" + self.author.first_name + " Wikipedia cannot get a result." self.client.send( Message(text=response_text, mentions= mentions), thread_id=self.thread_id, thread_type=self.thread_type )
def run(self): try: link = "https://www.theweathernetwork.com/ca/search?q=" for i in self.user_params: if i == "-t": break else: link += i + "%20" webpage = requests.get(link) text = str( bs4.BeautifulSoup(webpage.text, 'html.parser').find("li", class_="result")) h = text.find("href") e = text[h:].find(">") r = text[h:h + e] link = "https://www.theweathernetwork.com" + r[6:-1] response_text = "@" + self.author.first_name + " Check for yourself at " + link except: response_text = "@" + self.author.first_name + " Dude is that even a place." mentions = [ Mention(self.author_id, length=len(self.author.first_name) + 1) ] self.client.send(Message(text=response_text, mentions=mentions), thread_id=self.thread_id, thread_type=self.thread_type)
def run(self): seed(randint(0, 100)) mentions = [ Mention(self.author_id, length=len(self.author.first_name) + 1) ] if len(self.user_params) > 0: if self.user_params[0] == "help": response_text = "@" + self.author.first_name response_text += "These are the possible react commands: \n```" for x in self.emoji_dict.keys(): response_text += "\n{}".format(x) response_text += "\n```" self.client.send(Message(text=response_text, mentions=mentions), thread_id=self.thread_id, thread_type=self.thread_type) exit() m = self.message_object reply_id = find_reply_id(m) try: emoji = self.find_reaction_emoji() if emoji != "invalid": self.client.reactToMessage(reply_id, self.find_reaction_emoji()) except FBchatException: response_text = "@{}\nPlease select a message to reply to before reacting.".format( self.author.first_name) self.client.send(Message(text=response_text, mentions=mentions), thread_id=self.thread_id, thread_type=self.thread_type)
def find_reaction_emoji(self): mentions = [Mention(self.author_id, length=len(self.author.first_name) + 1)] if len(self.user_params) == 0: return None elif len(self.user_params) == 1: emoji = self.user_params[0].strip().lower() try: emoji = MessageReaction(emoji) return emoji except ValueError: try: emoji = self.emoji_dict[emoji] if emoji == "run_random": emoji = choose(["❤", "😍", "😆", "😮", "😢", "😠", "👍", "👎"]) return MessageReaction(emoji) except KeyError: response_text = "@{}\nSorry, you can't react with that.".format(self.author.first_name) self.client.send( Message(text=response_text, mentions=mentions), thread_id=self.thread_id, thread_type=self.thread_type ) return "invalid" else: response_text = "@{}\nPlease input only 1 emoji.".format(self.author.first_name) self.client.send( Message(text=response_text, mentions=mentions), thread_id=self.thread_id, thread_type=self.thread_type ) return "invalid"
def run(self): response_text = "@" + self.author.first_name + "\nGood Videos Here:\nhttps://www.youtube.com/watch?v=3CQyYE1rMJg&t=6s\nhttps://www.youtube.com/watch?v=oHg5SJYRHA0\nhttps://www.youtube.com/watch?v=cPJUBQd-PNM\nhttps://www.youtube.com/watch?v=2bHBUs-k3ac\nhttps://www.youtube.com/watch?v=dgha9S39Y6M\nhttps://www.youtube.com/watch?v=c5daGZ96QGU" mentions = [ Mention(self.author_id, length=len(self.author.first_name) + 1) ] self.client.send(Message(text=response_text, mentions=mentions), thread_id=self.thread_id, thread_type=self.thread_type)
def message_with_mentions(request, client, client2, group): text = "Hi there [" mentions = [] if "me" in request.param: mentions.append( Mention(thread_id=client.uid, offset=len(text), length=2)) text += "me, " if "other" in request.param: mentions.append( Mention(thread_id=client2.uid, offset=len(text), length=5)) text += "other, " # Unused, because Facebook don't properly support sending mentions with groups as targets if "group" in request.param: mentions.append( Mention(thread_id=group["id"], offset=len(text), length=5)) text += "group, " text += "nothing]" return Message(text, mentions=mentions)
def tag_all(client, author_id, message_object, thread_id, thread_type): gc_thread = Client.fetchThreadInfo(client, thread_id)[thread_id] mention_list = [] message_text = '@all' for person in Client.fetchAllUsersFromThreads(self=client, threads=[gc_thread]): mention_list.append(Mention(thread_id=person.uid, offset=0, length=1)) client.send(Message(text=message_text, mentions=mention_list), thread_id=thread_id, thread_type=thread_type)
def run(self): if self.client.uid != self.author_id: mentions = [ Mention(self.author_id, length=len(self.author.first_name) + 1) ] self.client.send( Message(text="@" + self.author.first_name.upper() + " WATCH YOUR LANGUAGE", mentions=mentions), thread_id=self.thread_id, thread_type=self.thread_type)
def run(self): response_text = "@" + self.author.first_name mentions = [ Mention(self.author_id, length=len(self.author.first_name) + 1) ] url = "http://yerkee.com/api/fortune" response_text += " " + requests.get(url).json()['fortune'] self.client.send(Message(text=response_text, mentions=mentions), thread_id=self.thread_id, thread_type=self.thread_type)
def run(self): response_text = "@" + self.author.first_name + "\nCheck our website out at https://vikingsdev.ca\n Events: " \ "vikingsdev.ca/events\n Workshops: vikingsdev.ca/workshops\n " \ "Sign Up: vikingsdev.ca/signup " mentions = [ Mention(self.author_id, length=len(self.author.first_name) + 1) ] self.client.send(Message(text=response_text, mentions=mentions), thread_id=self.thread_id, thread_type=self.thread_type)
def run(self): response_text = "@{}".format(self.author.first_name) if len(self.user_params) == 0: response_text += " Please signify which part (1-4) of the commands list you would like to see." elif len(self.user_params) == 1: try: # sends general information about all commands start = 0 end = len(modules) if float(self.user_params[0]) == 1: response_text += " Part 1/4" end = math.ceil(len(modules) / 4) elif float(self.user_params[0]) == 2: response_text += " Part 2/4" start = math.ceil(len(modules) / 4) end = math.ceil(len(modules) / 2) elif float(self.user_params[0]) == 3: response_text += " Part 3/4" start = math.ceil(len(modules) / 2) end = math.ceil(3 * len(modules) / 4) elif float(self.user_params[0]) == 4: response_text += " Part 4/4" start = math.ceil(3 * len(modules) / 4) for x in modules[start:end]: instance = self.get_instance(x) response_text += "\n\n!" + x + ": " + instance.documentation[ "function"] response_text += "\n\nIf you want to learn more about a specific command, send '!help !COMMAND_NAME'." except ValueError: # sends detailed information about a specific command c_name = str(self.user_params[0]).replace("!", "", 1) print(c_name) print(modules) if c_name in modules: instance = self.get_instance(c_name) response_text += """ \nThe !{} command: \nFunction: {} \nParameters: {} """.format(c_name, instance.documentation["function"], instance.documentation["parameters"]) else: response_text += "\nlol good try" else: response_text += "\nSorry, we can only provide information on one command at a time!" \ + "\nPlease use the format: '!help !COMMAND_NAME'" mentions = [ Mention(self.author_id, length=len(self.author.first_name) + 1) ] self.client.send(Message(text=response_text, mentions=mentions), thread_id=self.thread_id, thread_type=self.thread_type)
def run(self): if self.client.uid == self.author_id or self.author_id == "100045950177697": return replied_to: Message = self.message_object.replied_to for s in statuses: if s in self.message_object.text.lower(): status = s break else: status = "unconfirmed" if replied_to: bruh_moment = replied_to.text bro = replied_to.author else: messages = self.client.fetchThreadMessages(thread_id=self.thread_id, limit=10) messages.reverse() for m, i in zip(messages, range(len(messages))): if self.message_object.uid == m.uid: bruh_moment = messages[i - 1].text bro = messages[i - 1].author trigger = self.message_object.text messenger_ref = self.gdb.collection(u'bruhs').document(u'messenger') thread_sharing = messenger_ref.get().to_dict()['threads'] if self.thread_id not in thread_sharing: thread_sharing[self.thread_id] = {"shared": []} messenger_ref.update({u'threads': thread_sharing}) messenger_bruhs = messenger_ref.get().to_dict()['latest_id'] bruh_doc = messenger_ref.collection(u'bruhs').document(str(messenger_bruhs + 1)) bruh_doc.set({ u'trigger': trigger, u'moment': bruh_moment, u'thread': self.thread_id, u'author': self.author_id, u'bro': bro, u'status': status, u'time': int(time.time()) }) messenger_ref.update({u'latest_id': messenger_bruhs + 1}) response_text = """ @{} Thank you for your entry. Bruh #{} has been logged into the Bruh Database. """.format(self.author.first_name, messenger_bruhs + 1) mentions = [Mention(self.author_id, length=len(self.author.first_name) + 1)] self.client.send( Message(text=response_text, mentions=mentions), thread_id=self.thread_id, thread_type=self.thread_type )
def run(self): if len(self.user_params) > 0: uni = " ".join(self.user_params) response_text = "@" + self.author.first_name + "\nu op guaranteed acceptance at " + uni else: response_text = "@" + self.author.first_name + "\nu op guaranteed acceptance at HYPSM" mentions = [ Mention(self.author_id, length=len(self.author.first_name) + 1) ] self.client.send(Message(text=response_text, mentions=mentions), thread_id=self.thread_id, thread_type=self.thread_type)
def run(self): response = json.loads( requests.get("https://api.github.com/rate_limit").text) remaining = response['rate']['remaining'] response_text = """ @{}\nRemaining pings: {} """.format(self.author.first_name, remaining) mentions = [ Mention(self.author_id, length=len(self.author.first_name) + 1) ] self.client.send(Message(text=response_text, mentions=mentions), thread_id=self.thread_id, thread_type=self.thread_type)
def run(self): if self.author.first_name == "Charley": response_text = "Well @" + self.author.first_name + " I think your 12 rejections are statistically compelling enough..." elif len(self.user_params) > 0: response_text = "@" + self.author.first_name + "\n u op guaranteed acceptance at " + self.user_params[0] else: response_text = "@" + self.author.first_name + "\n u op guaranteed acceptance at HYPSM" mentions = [Mention(self.author_id, length=len(self.author.first_name) + 1)] self.client.send( Message(text=response_text, mentions=mentions), thread_id=self.thread_id, thread_type=self.thread_type )
def run(self): response_text = """ @{} \nYou can contribute to Dentaku here: https://github.com/VikingsDev/Dentaku \nFor more information, check out VikingsDev Bounties: https://vikingsdev.ca/bounties \nHappy contributing! """.format(self.author.first_name) mentions = [ Mention(self.author_id, length=len(self.author.first_name) + 1) ] self.client.send(Message(text=response_text, mentions=mentions), thread_id=self.thread_id, thread_type=self.thread_type)
def run(self): msg = self.message_object.text.translate( str.maketrans('', '', string.punctuation)).lower() trigger = msg.find("ass") if self.client.uid != self.author_id and (trigger == 0 or msg[trigger-1] == " ")\ and (trigger + 3 == len(msg) or msg[trigger+3] == " "): mentions = [ Mention(self.author_id, length=len(self.author.first_name) + 1) ] self.client.send(Message(text="@" + self.author.first_name + " I like ass.", mentions=mentions, reply_to_id=self.message_object.uid), thread_id=self.thread_id, thread_type=self.thread_type)
def tag_all(client, author_id, message_object, thread_id, thread_type): """Tags everyone in the chat""" gc_thread = Client.fetchThreadInfo(client, thread_id)[thread_id] mention_list = [] message_text = '@all' for person in Client.fetchAllUsersFromThreads(self=client, threads=[gc_thread]): mention_list.append(Mention(thread_id=person.uid, offset=0, length=1)) action_queue.put( Action(client, 'message', thread_id, thread_type, text=message_text, mentions=mention_list))
def run(self): mentions = [ Mention(self.author_id, length=len(self.author.first_name) + 1) ] response_text = "@" + self.author.first_name if len(self.user_params) == 0: response_text += " Please enter a city" elif self.user_params[0].lower() != "help": try: url = "http://api.openweathermap.org/data/2.5/forecast?q={}&units=metric&APPID=6f68045e525e16f8232fb0e5f19987c4".format( "%20".join(self.user_params)) jsonurl = urlopen(url) info = json.loads(jsonurl.read()) response_text += " Weather at "+ info['city']['name'] + ", " + info['city']['country'] +\ "\n Population: " + str(info['city']['population']) info = info['list'][0] response_text += "\nCurrent temperature: " + str( info['main']['temp']) + "ºC" response_text += "\n\nMore info at " except: response_text += "Check for yourself at " try: link = "https://www.theweathernetwork.com/ca/search?q=" for i in self.user_params: if i == "-t": break else: link += i + "%20" webpage = requests.get(link) text = str( bs4.BeautifulSoup(webpage.text, 'html.parser').find("li", class_="result")) h = text.find("href") e = text[h:].find(">") r = text[h:h + e] link = "https://www.theweathernetwork.com" + r[6:-1] response_text += link except: response_text = "@" + self.author.first_name + " Dude is that even a place." response_text += " \nFor a full list of commands type !weather help" else: response_text += " Possible Commands to add after the city:\nsunset, sunrise" self.client.send(Message(text=response_text, mentions=mentions), thread_id=self.thread_id, thread_type=self.thread_type)
def run(self): response_text = """ @ + {} + \n!website: Website Info \n!help: Shows list of commands \n!good_video: List of videos. \n!countdown [num]: Counts down from num. \n!contribute: Learn how to be a bounty hunter. """.format(self.author.first_name) mentions = [ Mention(self.author_id, length=len(self.author.first_name) + 1) ] self.client.send(Message(text=response_text, mentions=mentions), thread_id=self.thread_id, thread_type=self.thread_type)
def run(self): response_text = ("@{}" "\nI am currently on deployment #{}." "\nLast deployment was at {}").format( self.author.first_name, self.database['deployment'], time.strftime( '%Y-%m-%d %-I:%M %p', time.localtime( self.database['last_deployment_time']))) mentions = [ Mention(self.author_id, length=len(self.author.first_name) + 1) ] self.client.send(Message(text=response_text, mentions=mentions), thread_id=self.thread_id, thread_type=self.thread_type)
def run(self): try: count = int(self.user_params[0]) if count > 10: response_text = "I'm too lazy to do that..." elif count <= 0: response_text = "Lets do it again!" else: response_text = "!countdown " + str(count - 1) mentions = [ Mention(self.author_id, length=len(self.author.first_name) + 1) ] except ValueError: response_text = "You think you're soooo clever? Not anymore " + self.author.first_name + ", because I now have error catching!" self.client.send(Message(text=response_text), thread_id=self.thread_id, thread_type=self.thread_type)
def matrix_to_facebook(content: TextMessageEventContent, room_id: RoomID) -> 'SendParams': mentions = [] reply_to_id = None if content.relates_to.rel_type == RelationType.REFERENCE: message = DBMessage.get_by_mxid(content.relates_to.event_id, room_id) if message: content.trim_reply_fallback() reply_to_id = message.fbid if content.format == Format.HTML and content.formatted_body: parsed = MatrixParser.parse(content.formatted_body) text = parsed.text mentions = [Mention(thread_id=mention.extra_info['fbid'], offset=mention.offset, length=mention.length) for mention in parsed.entities] else: text = content.body return {"text": text, "mentions": mentions, "reply_to_id": reply_to_id}
def run(self): if not self.user_params: response_text = "@{} Test mode is currently {} which corresponds to \"{}\" in database.json. This means that the bot can{} accept group chat commands.".format( self.author.first_name, 'on' if self.database['testing'] == "y" else 'off', self.database['testing'], ' *not*' if self.database['testing'] == "y" else '') elif self.user_params[0].lower() == "on" or self.user_params[0].lower( ) == "off" or self.user_params[0].lower( ) == "y" or self.user_params[0].lower() == "n": if self.client.uid == self.author_id: self.database['testing'] = 'y' if self.user_params[0].lower( ) == "on" or self.user_params[0].lower() == "y" else 'n' response_text = "@{} Test mode has been set to {}, which corresponds to \"{}\" in database.json.".format( self.author.first_name, self.user_params[0], self.database['testing']) else: response_text = "@{} You do not have sufficient permissions to change this mode.".format( self.author.first_name) elif self.user_params[0] == "t" or self.user_params[0] == "toggle": if self.client.uid == self.author_id: if 'testing' in self.database: if self.database['testing'] == 'y': self.database['testing'] = 'n' else: self.database['testing'] = 'y' response_text = "@{} Testing mode has been turned {}".format( self.author.first_name, ('on' if self.database['testing'] == 'y' else 'off')) else: response_text = "@{} No mode has been set yet. Run `!testing on` or `!testing off` to set a mode.".format( self.author.first_name) else: response_text = "@{} You do not have sufficient permissions to change this mode.".format( self.author.first_name) self.save_db() mentions = [ Mention(self.author_id, length=len(self.author.first_name) + 1) ] self.client.send(Message(text=response_text, mentions=mentions), thread_id=self.thread_id, thread_type=self.thread_type)
def run(self): mentions = [ Mention(self.author_id, length=len(self.author.first_name) + 1) ] try: link = "https://www.urbandictionary.com/define.php?term=" for i in self.user_params: link += i + "+" link = link[:-1] req = requests.get(link) soup = bs4.BeautifulSoup(req.text, 'html.parser') response_text = "@" + self.author.first_name + "\n" + soup.find_all( "div", class_="meaning")[0].get_text() except: response_text = "@" + self.author.first_name + " Your query was not valid or may not exit on UD. Please try again." self.client.send(Message(text=response_text, mentions=mentions), thread_id=self.thread_id, thread_type=self.thread_type)
def remind(client, author_id, message_object, thread_id, thread_type): msg = message_object.text.split(' ', 1)[1] try: print("Parsing time....") reminder_date = search_dates(msg)[0] print("Got the time") except TypeError: action_queue.put( Action( client, 'message', thread_id, thread_type, text="Maybe I'm dumb but I can't find a date in that message.") ) return reminder_content = msg.replace(reminder_date[0] + " ", '') if reminder_date[1].replace(microsecond=0) in reminders: reminders[reminder_date[1].replace(microsecond=0)].append( Action(client, 'message', thread_id, thread_type, text=f"Reminder: {reminder_content}")) else: reminders[reminder_date[1].replace(microsecond=0)] = [ Action(client, 'message', thread_id, thread_type, text=f"Reminder: {reminder_content}", mentions=[Mention(thread_id=author_id, offset=0, length=1)]) ] action_queue.put( Action( client, 'message', thread_id, thread_type, text= f"Ok, I'll remind you to {reminder_content} at {reminder_date[1].strftime('%x, %I:%M%p')}" ))
def run(self): link = "https://vikingsdev.ca/events.html" webpage = requests.get(link) source = bs4.BeautifulSoup(webpage.text, 'html.parser') title = str(source.find("h4", class_="mb-2").getText()) date = str(source.find("span", class_="subheading").getText()) loc = str(source.find_all("span", class_="subheading")[1].getText()) reg = str(source.find("a", string="REGISTER")) reg = reg[reg.find("href") + 6:reg.find(">", reg.find("href")) - 1] ml = str(source.find("a", string="Mailing List")) ml = ml[ml.find("href") + 6:ml.find(">", ml.find("href")) - 1] response_text = "@" + self.author.first_name + "\nThe closest hackathon is " + title + "\nDate: " + \ date + "\nLocation: " + loc + "\nRegister at: " + reg + "\nMailing List: " + ml mentions = [ Mention(self.author_id, length=len(self.author.first_name) + 1) ] self.client.send(Message(text=response_text, mentions=mentions), thread_id=self.thread_id, thread_type=self.thread_type)
def test_mention_from_range(): data = {"length": 17, "offset": 0, "entity": {"__typename": "User", "id": "1234"}} assert Mention(thread_id="1234", offset=0, length=17) == Mention._from_range(data) data = { "length": 2, "offset": 10, "entity": {"__typename": "MessengerViewer1To1Thread"}, } assert Mention(thread_id=None, offset=10, length=2) == Mention._from_range(data) data = { "length": 5, "offset": 21, "entity": {"__typename": "MessengerViewerGroupThread"}, } assert Mention(thread_id=None, offset=21, length=5) == Mention._from_range(data)