Skip to content
Snippets Groups Projects
Commit 4411d901 authored by Sydney Anne Erickson's avatar Sydney Anne Erickson :chipmunk:
Browse files

Update discord_bot.py, telegram_bot.py files

parent 29b685c8
Branches
No related tags found
No related merge requests found
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())
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment