Skip to content

Instantly share code, notes, and snippets.

@brudil
Last active August 15, 2018 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brudil/445c88b8bea9771d90dc7921a657b15f to your computer and use it in GitHub Desktop.
Save brudil/445c88b8bea9771d90dc7921a657b15f to your computer and use it in GitHub Desktop.
bot = Bot()
# register adds the function to the bot
# accepts a tuple of different triggers
@bot.register(('!weather {location?}', '☀️')) # question mark means it isn't required
def weather(msg, res, location = 'brighton'): # arguments get passed in after msg, res.
data = requests.get(f'weatherapi.com/{location}')
# msg contains all data related to the message sent
# res handles everything being sent back
res.send(f'Today it is going to be {data.overview} with lows of {data.low} and highs of {data.high}')
@bot.register('!russianroullet')
def russian(msg, res):
# use msg to access all infomation, such as current thread -> members
shuffled_members = shuffle(msg.thread.members)
kill = randomint(0, len(shuffled_members) - 1)
# sending accepts a delay in milliseconds
res.send('Loading gun...', delay=100)
for member, index in enumerate(shuffled_members):
if index == kill:
# send after queues it for after the previous message
# type_for delays it for x milliseconds and sends the typing indicator for suspense
res.send_after(f'{member.name} is dead', delay=4000, type_for=300)
# queue 'actions' just like messages
res.action_after(member, 'kick', delay=1000)
break
else:
res.send_after(f'BANG {member.name} is safe')
# starts the listening process with an instance of fbchat
bot.listen(fbchat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment