Skip to content

Instantly share code, notes, and snippets.

@iamgroot42
Created June 15, 2019 09:56
Show Gist options
  • Save iamgroot42/85de8d64f51d8074f7852a982f3d341c to your computer and use it in GitHub Desktop.
Save iamgroot42/85de8d64f51d8074f7852a982f3d341c to your computer and use it in GitHub Desktop.
Random bot : sends random responses. A fun-to-have bot for any group conversation :)
import numpy as np
import random
import getpass
import requests
import time
from telegram import Bot, ParseMode
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
def logger(ctype, command):
print("[" + ctype + "] : " + command)
def get_a_meme():
tags = ["cow", "moo", "goat", "tomato", "potato", "cooker", "pubg", "dance"]
query = tags[np.random.randint(len(tags))]
url = "https://api.giphy.com/v1/gifs/search?api_key=INSERT_GIPHY_TOKEN_HERE&q=%s&limit=25&offset=0&rating=G&lang=en" % query
r = requests.get(url)
gifs = [x["url"] for x in r.json()["data"]]
return gifs[np.random.randint(len(gifs))]
def oh():
o_ = np.random.randint(1, 3)
h_ = np.random.randint(1, 3)
return ("o" * o_) + ("h" * h_)
def xd():
x_ = np.random.randint(1, 2)
d_ = np.random.randint(1, 2)
D_ = np.random.randint(2, 5)
ds = ("d" * d_) + ("D" * d_)
return ("x" * x_) + ''.join(random.sample(ds, len(ds)))
def bhb():
variations = ["bhb", "BHB", "bohot badiya", "bohot HI badiya", "....chap", "ABEY CHALLLlkllllLL"]
return variations[np.random.randint(len(variations))]
def haha():
ha_ = np.random.randint(1, 3)
Ha_ = np.random.randint(1, 3)
hA_ = np.random.randint(1, 3)
HA_ = np.random.randint(1, 3)
j_ = np.random.randint(1, 3)
segments = ["ha" * ha_, "Ha" * Ha_, "hA" * hA_, "HA" * HA_, "j" * j_]
return "".join(np.random.permutation(segments))
def sarcasm():
variations = [":)", "...", "...nvm", "ye dekho", "denied", "DENIED", "waaah", "amaze", "wtfffffff", "well wtf", "wtaf", "I see"]
return variations[np.random.randint(len(variations))]
def school_story():
start = "ek baar mai school jaa rha tha"
midway_bs_1 = ["and mere haath mein calendar tha", "and then mujhe cooker dikha", "and then a cow said moo", "but then it started to rain", "and then ghar pe doodh khatam ho gaya", "and then mujhe raste mein mansi mili", "phir nhi gaya", "and then JALEBI MIL GAYI"]
midway_bs_2 = ["to maine bola 'hi' and mai school nahi gaya", "to fir maine kela khaa liya and I topped class", "to fir i danced and then school nahi gaya", "to fir i asked for DD and then school nahi gaya", "kyunki mujhe laga ye hojayega", "kyunki mai strawberry hoon\naur mujhe laga ki logon se itni sweetness handle nhi hogi", "Kyonki mujhe laga ki itni beauty handle nhi hogi bachon se"]
end_bs = ["thnx", "thx", "ty ty", ":D", ":')"]
mid_1 = midway_bs_1[np.random.randint(len(midway_bs_1))]
mid_2 = midway_bs_2[np.random.randint(len(midway_bs_2))]
return "\n".join([start, mid_1, mid_2, end_bs[np.random.randint(len(end_bs))]])
def well():
w_ = np.random.randint(2, 3)
e_ = np.random.randint(1, 4)
l_ = np.random.randint(2, 7)
return ("w" * w_) + ("e" * e_) + ("l" * l_)
def short_circuit():
variations = ["xzd", "yes", "COOKER KA __DHAKKAN__", "ANGOOR __KHATTE__ HAIN :*", "jalebi **MILEGI** !", "mooooooooo", "dil mein mere hai...kaaju pistooo", "ae DD", "tu..tu..tu..MERIII", "acha acha", "mai..JALPARI hoon"]
return variations[np.random.randint(len(variations))]
def random_love():
variations = [":*", "kya sexy lag raha hai", ":*****", "dashing <3", "bhai mazze aa gaye ;)"]
return variations[np.random.randint(len(variations))]
def twss():
return "twss"
def random_trigger():
return ["arre bol", "bol na", "bolti band kyu ho gayi?", "ARRRE???", "BOLLL NAAA", "FATT GAYI KYA?!?!??!?!", "BOLLLL!!"]
def random_shock():
o_ = np.random.randint(1, 3)
h_ = np.random.randint(1, 3)
b_ = np.random.randint(1, 3)
h2_ = np.random.randint(1, 3)
a_ = np.random.randint(1, 3)
i_ = np.random.randint(1, 3)
return ("o" * o_) + ("h" * h_) + " " + ("b" * b_) + ("h" * h2_) + ("a" * a_) + ("i" * i_)
def signature_move():
c_ = np.random.randint(1, 3)
h_ = np.random.randint(1, 3)
a_ = np.random.randint(1, 3)
k_ = np.random.randint(2, 5)
e_ = np.random.randint(0, 2)
return ("c" * c_) + ("h" * h_) + ("a" * a_) + ("k" * k_) + ("e" * e_)
def best_comeback(x):
t_ = np.random.randint(1, 2)
u_ = np.random.randint(2, 4)
return ("T" * t_) + ("U" * u_) + " " + x
def iamambar(bot, update):
silence_probability = -0.5
if np.random.random_sample() < silence_probability:
shortlisted_text = ""
else:
available_responses = [random_love, twss, signature_move, random_shock, short_circuit, well, school_story, sarcasm, haha, bhb, xd, oh, get_a_meme]
picked = np.random.randint(len(available_responses) + 2)
if picked == len(available_responses):
shortlisted_text = best_comeback(update.message.text)
bot.sendMessage(chat_id=update.message.chat_id, text=shortlisted_text, parse_mode = ParseMode.MARKDOWN)
elif picked == len(available_responses) + 1:
for message in random_trigger():
bot.sendMessage(chat_id=update.message.chat_id, text=message, parse_mode = ParseMode.MARKDOWN)
time.sleep(1)
else:
shortlisted_text = available_responses[picked]()
bot.sendMessage(chat_id=update.message.chat_id, text=shortlisted_text, parse_mode = ParseMode.MARKDOWN)
def error(update, context):
logger.warning('Update "%s" caused error "%s"', update, context.error)
# Token for bot
token = getpass.getpass("Enter API token for bot: ")
if __name__ == "__main__":
# Set up Bot
updater = None
try:
updater = Updater(token=token)
except:
logger("ERROR", "Invalid Token")
exit()
# Add handlers to dispatcher
dp = updater.dispatcher
dp.add_handler(MessageHandler(Filters.all, iamambar))
# Start polling Telegram
print("Virtual Ambar is up!")
dp.add_error_handler(error)
updater.start_polling()
updater.idle()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment