From 6e131e999939eac0e41563f2a37e7b954f821584 Mon Sep 17 00:00:00 2001 From: inexcode Date: Thu, 24 Jan 2019 20:39:28 +0300 Subject: [PATCH] Init --- config.json | 10 +++++ plugins/__init__.py | 0 plugins/coffee.py | 102 ++++++++++++++++++++++++++++++++++++++++++ plugins/dicer.py | 22 +++++++++ plugins/references.py | 35 +++++++++++++++ 5 files changed, 169 insertions(+) create mode 100644 config.json create mode 100644 plugins/__init__.py create mode 100644 plugins/coffee.py create mode 100644 plugins/dicer.py create mode 100644 plugins/references.py diff --git a/config.json b/config.json new file mode 100644 index 0000000..342bcdd --- /dev/null +++ b/config.json @@ -0,0 +1,10 @@ +{ + "token": "", + "bot": { + "plugins": [ + "plugins.dicer", + "plugins.references", + "plugins.coffee" + ] + } +} \ No newline at end of file diff --git a/plugins/__init__.py b/plugins/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/plugins/coffee.py b/plugins/coffee.py new file mode 100644 index 0000000..dd4ff33 --- /dev/null +++ b/plugins/coffee.py @@ -0,0 +1,102 @@ +from disco.bot import Bot, Plugin +import rolldice +from enum import Enum + +class Drinks(Enum): + espresso = (1, "Эспрессо") + americano = (2, "Американо") + cappuccino = (3, "Капучино") + latte = (4, "Латте") + raf = (5, "Раф-кофе") + flat_white = (6, "Флэт Уайт") + mocachino = (7, "Мокаччино") + frappuchino = (8, "Фраппучино") + hot_chocolate = (9, "Горячий шоколад") + cacao = (10, "Какао") + milk_coctail = (11, "Молочный коктейль") + tea = (12, "Чай") + + enjoy1 = (13, "Латте бельгийская вафля") + enjoy2 = (14, "Арахисовый капучино") + enjoy3 = (15, "Капучино кокосовый бисквит") + enjoy4 = (16, "Лавандовый раф") + enjoy5 = (17, "Грушевый раф с солёной карамелью") + enjoy6 = (18, "Чай с вишней и пряностями") + + latte_tea = (19, "Латте чай") + + feel_winter1 = (20, "Хвойный раф") + feel_winter2 = (21, "Раф грецкий орех в клиновом сиропе") + feel_winter3 = (22, "Чай шиповник-липа") + feel_winter4 = (23, "Чай японский лимон Юзу") + + def __init__(self, id, title): + self.id = id + self.title = title + +class Syrops(Enum): + syroup1 = (1, "Карамель") + syroup2 = (2, "Солёная карамель") + syroup3 = (3, "Банан") + syroup4 = (4, "Ваниль") + syroup5 = (5, "Миндаль") + syroup6 = (6, "Кокос") + syroup7 = (7, "Кленовый") + syroup8 = (8, "Клубника") + syroup9 = (9, "Чёрная смородина") + syroup10 = (10, "Имбирный пряник") + syroup11 = (11, "Личи") + syroup12 = (12, "Шоколад") + syroup13 = (13, "Амаретто") + syroup14 = (14, "Ирландский крем") + sugar = (15, "Ванильный сахар") + combo1 = (16, "Солёная карамель и имбирный пряник") + + def __init__(self, id, title): + self.id = id + self.title = title + + +class Teas(Enum): + green = (1, "Зелёный") + black = (2, "Чёрный") + fruit = (3, "Фруктовый") + + def __init__(self, id, title): + self.id = id + self.title = title + + +class CoffeePlugin(Plugin): + @Plugin.command('coffee', '[param:str]') + def on_coffee(self, event, param=''): + try: + result = "" + if param.lower() == 'classic': + result1, expl1 = rolldice.roll_dice('1d12') + elif param.lower() == 'raf': + result1, expl1 = (5, 'User') + else: + result1, expl1 = rolldice.roll_dice('1d23') + result += list(Drinks)[result1-1].title + if result1 == 5: + result2, expl2 = rolldice.roll_dice('1d18') + if result2 > 16: + result2, expl2 = rolldice.roll_dice('1d15') + result21, expl21 = rolldice.roll_dice('1d15') + result += "\n**Сиропы**: {} и {}".format(list(Syrops)[result2 - 1].title, list(Syrops)[result21 - 1].title) + else: + result += "\n**Сироп**: {}".format(list(Syrops)[result2 - 1].title) + elif result1 == 9: + result2, expl2 = rolldice.roll_dice('1d2') + if result2 == 1: + result += "\nТёмный" + else: + result += "\nМолочный" + elif result1 == 12 or result1 == 19: + result2, expl2 = rolldice.roll_dice('1d3') + result += " {}".format(list(Teas)[result2 - 1].title) + except Exception as e: + event.msg.reply(str(e)) + else: + event.msg.reply(result) diff --git a/plugins/dicer.py b/plugins/dicer.py new file mode 100644 index 0000000..091ff74 --- /dev/null +++ b/plugins/dicer.py @@ -0,0 +1,22 @@ +from disco.bot import Bot, Plugin +import rolldice + + +class TestPlugin(Plugin): + @Plugin.command('roll', ' [comment:str...]') + def on_roll(self, event, dice, comment=''): + try: + result, explanation = rolldice.roll_dice(dice) + except rolldice.DiceGroupException as e: + event.msg.reply(str(e)) + except rolldice.DiceOperatorException as e: + event.msg.reply(str(e)) + except Exception as e: + event.msg.reply(str(e)) + else: + if comment: + event.msg.reply( + '{} rolled *{}* \n **{}** \t`{}`'.format(str(event.msg.author)[:-5], comment, result, explanation)) + else: + event.msg.reply( + '{} rolled a dice! \n **{}** \t`{}`'.format(str(event.msg.author)[:-5], result, explanation)) diff --git a/plugins/references.py b/plugins/references.py new file mode 100644 index 0000000..07f594d --- /dev/null +++ b/plugins/references.py @@ -0,0 +1,35 @@ +from disco.bot import Bot, Plugin +from disco.types.message import MessageEmbed +import firebase_admin +from firebase_admin import credentials +from firebase_admin import db + +# Auth +cred = credentials.Certificate('firebase-key.json') +firebase_admin.initialize_app(cred, { + 'databaseURL': 'https://.firebaseio.com' +}) + + +class RefPlugin(Plugin): + @Plugin.command('ref', '') + def on_red(self, event, character): + try: + dbref = db.reference('references/{}'.format(character.lower())) + data = dbref.get() + if data: + embed = MessageEmbed() + embed.set_author(name=data.get('owner', 'Unknown owner'), url=data.get('ownerURL'), icon_url=data.get('ownerAvatar')) + embed.title = data.get('name', 'Unnamed') + if data.get('description'): + embed.description = data['description'] + embed.color = data['color'] + if data.get('image'): + embed.set_image(url=data['image']) + if data.get('thumbnail'): + embed.set_thumbnail(url=data['thumbnail']) + event.msg.reply(embed=embed) + else: + event.msg.reply("Not found") + except Exception as e: + event.msg.reply(str(e))