Compare commits
2 Commits
e897d6c162
...
83a79b7b24
Author | SHA1 | Date |
---|---|---|
Ceda EI | 83a79b7b24 | |
Ceda EI | 4ae5663fea |
|
@ -95,3 +95,4 @@ ENV/
|
||||||
.ropeproject
|
.ropeproject
|
||||||
|
|
||||||
config.py
|
config.py
|
||||||
|
chanbot.sqlite
|
||||||
|
|
32
bot.py
32
bot.py
|
@ -1,15 +1,41 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
|
|
||||||
|
import logging
|
||||||
import config
|
import config
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from telegram.ext import Updater, MessageHandler, Filters
|
from telegram.ext import Updater, MessageHandler, Filters
|
||||||
|
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
|
||||||
|
|
||||||
|
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - \
|
||||||
|
%(message)s', level=logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
def main(bot, update, db):
|
def get_callback_id(db):
|
||||||
|
cursor = db.cursor()
|
||||||
|
query = ('SELECT max(callback) FROM poll')
|
||||||
|
cursor.execute(query)
|
||||||
|
return int(cursor.fetchone()[0]) + 1
|
||||||
|
|
||||||
|
|
||||||
|
def add_vote(db, callback_id, user_id):
|
||||||
|
cursor = db.cursor()
|
||||||
|
query = ("INSERT INTO poll(callback, user_id) values(?,?)")
|
||||||
|
cursor.execute(query, (callback_id, user_id))
|
||||||
|
db.commit()
|
||||||
|
|
||||||
|
|
||||||
|
def post(bot, update, db):
|
||||||
chat_id = update.message.chat_id
|
chat_id = update.message.chat_id
|
||||||
if chat_id in config.allowed_users:
|
if chat_id in config.allowed_users:
|
||||||
pass
|
callback_id = get_callback_id(db)
|
||||||
|
add_vote(db, callback_id, 0)
|
||||||
|
photo = update.message.photo[0]
|
||||||
|
file_id = photo.file_id
|
||||||
|
keyboard = InlineKeyboardMarkup([[InlineKeyboardButton(text="❤️",
|
||||||
|
callback_data=callback_id)]])
|
||||||
|
bot.send_photo(chat_id=config.channel_id, photo=file_id,
|
||||||
|
reply_markup=keyboard)
|
||||||
else:
|
else:
|
||||||
bot.send_message(chat_id=chat_id, text="Not Authorized")
|
bot.send_message(chat_id=chat_id, text="Not Authorized")
|
||||||
|
|
||||||
|
@ -20,6 +46,6 @@ dispatcher = updater.dispatcher
|
||||||
db = sqlite3.connect("chanbot.sqlite", check_same_thread=False)
|
db = sqlite3.connect("chanbot.sqlite", check_same_thread=False)
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
|
|
||||||
dispatcher.add_handler(MessageHandler(Filters.photo, lambda x, y: main(x,
|
dispatcher.add_handler(MessageHandler(Filters.photo, lambda x, y: post(x,
|
||||||
y, db)))
|
y, db)))
|
||||||
updater.start_polling()
|
updater.start_polling()
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
CREATE TABLE IF NOT EXISTS poll(callback int NOT NULL, user_id int, UNIQUE(callback, user_id));
|
||||||
|
INSERT INTO poll values(0, 0);
|
Loading…
Reference in New Issue