From 4411d9011ccc567c6bf0bf21f1501c76f225dcc1 Mon Sep 17 00:00:00 2001 From: Sydney Anne Erickson <sydney@elixxir.io> Date: Tue, 9 Nov 2021 17:26:12 +0000 Subject: [PATCH] Update discord_bot.py, telegram_bot.py files --- discord_bot.py | 40 +++++++++++++++++++++++++++++++++++ telegram_bot.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 discord_bot.py create mode 100644 telegram_bot.py diff --git a/discord_bot.py b/discord_bot.py new file mode 100644 index 0000000..c2b2b07 --- /dev/null +++ b/discord_bot.py @@ -0,0 +1,40 @@ +import discord +import dataset +from email.utils import parseaddr +# pip3 install discord dataset + +db = dataset.connect("sqlite:///discord.db") +usertable = db['usertable'] + +class MyClient(discord.Client): + async def on_ready(self): + print('Logged on as', self.user) + + async def on_message(self, message): + # don't respond to ourselves + if message.author == self.user: + return + + if not message.guild: + userOnList = usertable.find_one(user_id=str(message.author.id)) + + print(userOnList) + + if userOnList: + if len(message.content.strip().split(" ")) == 1 and "@" in message.content and \ + len(message.content.split("@")) == 2 and "." in message.content.split("@")[1]: + + usertable.upsert(dict(user_id=message.author.id, email=message.content), ["user_id"]) + + if userOnList["email"] == "": + await message.channel.send("You have been registered. Registration and login details will be sent to your email by November 19th. You will not be able to login until then.") + else: + await message.channel.send("Your email address has been updated. Registration and login details will be sent to your email by November 19th. You will not be able to login until then.") + else: + await message.channel.send("You are on our list! Please reply with a valid email address to register for the token sale.") + else: + await message.channel.send("You are not on the list of Discord community members as taken on 9PM UTC November 4th. Unfortunately, we cannot register you for this sale. If you think this is in error, please contact `sale@xx-coin.io`.") + +client = MyClient() +with open("discord.txt", "r") as f: + client.run(f.read()) diff --git a/telegram_bot.py b/telegram_bot.py new file mode 100644 index 0000000..b5d9573 --- /dev/null +++ b/telegram_bot.py @@ -0,0 +1,55 @@ +from aiogram import Bot, Dispatcher, executor, types +import dataset +import logging +# pip3 install aiogram dataset + +# Read token from telegram.txt +API_TOKEN = '' +with open("telegram.txt", "r") as f: + API_TOKEN = f.read().replace(" ", "").replace("\n", "").replace("\r", "") + +# Configure logging +logging.basicConfig(level=logging.INFO) + +# Initialise bot and dispatcher +bot = Bot(token=API_TOKEN) +dp = Dispatcher(bot) + +db = dataset.connect("sqlite:///telegram.db") +usertable = db['usertable'] + +@dp.message_handler() +async def on_message(message: types.Message) -> None: + print("Channel ID: ", message.chat.id, type(message.chat.id)) + + if message.chat.type == "private": + author_id = message.from_user.id + + userOnList = usertable.find_one(user_id=str(author_id)) + + if message.text.startswith("/start"): + if userOnList: + await message.answer("You are on our list! Please reply with a valid email address to register for the token sale.", reply=True) + return + else: + await message.answer("You are not on the list of Telegram community members as taken on 9PM UTC November 4th. Unfortunately, we cannot register you for this sale. If you think this is in error, please contact sale@xx-coin.io", reply=True) + return + + if userOnList: + if len(message.text.strip().split(" ")) == 1 and "@" in message.text and \ + len(message.text.split("@")) == 2 and "." in message.text.split("@")[1]: + + usertable.upsert(dict(user_id=author_id, email=message.text), ["user_id"]) + + if userOnList["email"] == "": + await message.answer("You have been registered. Registration and login details will be sent to your email by November 19th. You will not be able to login until then.", reply=True) + else: + await message.answer("Your email address has been updated. Registration and login details will be sent to your email by November 19th. You will not be able to login until then.", reply=True) + else: + await message.answer("You are on our list! Please reply with a valid email address to register for the token sale.", reply=True) + else: + await message.answer("You are not on the list of Telegram community members as taken on 9PM UTC November 4th. Unfortunately, we cannot register you for this sale. If you think this is in error, please contact sale@xx-coin.io", reply=True) + + +if __name__ == '__main__': + executor.start_polling(dp, skip_updates=True) -- GitLab