· 8 years ago · Feb 01, 2018, 05:50 PM
1import asyncio
2import json
3
4import codecs
5import os
6import random
7import re
8
9from cloudbot import hook
10from cloudbot.util import textgen
11
12nick_re = re.compile("^[A-Za-z0-9_|.\-\]\[\{\}]*$", re.I)
13
14#
15# https://github.com/CloudBotIRC/CloudBot/tree/master/plugins
16#
17# Hack5190 (at) gmail.com
18#
19# v1.0 - 1-Feb-2018 - Initial release
20#
21
22styles = ['New York', 'Boston', 'Montreal']
23
24bagels = ['Plain', 'Poppy-seed', 'Cinnamon Raisin', 'Whole Wheat', 'Onion', 'Garlic', 'Pumpernickel',
25 'Caraway', 'Black Russian', 'Sesame', 'Chocolate', 'Cheese', 'Blueberry', 'Mini',
26 'Chocolate Chip', 'Maple Syrup', 'Pumpkin', 'Rosemary', 'Oat', 'Jalapeño', 'Salt',
27 'Sour Dough', 'Banana Nut', 'French Toast', 'Asiago', 'Everything', 'Sun-dried Tomato']
28
29extras = ['Cream Cheese', 'Egg', 'Fresh Mozzarella', 'Prosciutto', 'Butter', 'Peanut Butter']
30
31def is_valid(target):
32 """ Checks if a string is a valid IRC nick. """
33 if nick_re.match(target):
34 return True
35 else:
36 return False
37
38
39@asyncio.coroutine
40@hook.command
41def bagel(text, action):
42 """<user> - gives <user> a bagel"""
43 user = text.strip()
44
45 if not is_valid(user):
46 return "I can't give a bagel to that user."
47
48 bagel_style = random.choice(styles)
49 bagel_type = random.choice(bagels)
50 bagel_extra = random.choice(extras)
51
52 action("prepares a {} style {} bagel with {} for {} and serves it with a smile, enjoy.".format(bagel_style, bagel_type, bagel_extra, user))