SteemSong. The start of the long-awaited bot. Main functionality.
Finally, I launched a bot written in Python with the main functionality. This is the implementation of the idea that is described in these posts:
https://steemit.com/steem/@alexmove/steem-song-telegram-bot
https://steemit.com/steemit/@alexmove/python-for-telegram-bot-create
I have a small group of enthusiasts who have already started testing the main functionality of the bot. More features will be added in the coming weeks. Namely:
- Authorization of participants. (!)
- Button "Cabinet"
- When you press the "Cabinet" button - a list of recorded audio and next to each number of likes and dislikes.
- Like and dislike buttons under each given audio message.
- Ability to click like and dislike to vote
- Admin - panel., with the ability to listen and delete messages.
- Counter of audio messages (how many) with the ability to output to the chat (where I will add the bot) on request. Those. output command the total number of audio in the database
- Ratings by the number of likes and dislikes
And here's the question - since I also make changes to the bot, what should I do, maybe on the github? I still don’t really know how to synchronize with him, I can order, but I can’t synchronize)
Bot: http://t.me/Steemsong_bot
main.py
import telebot
from telebot import types
from datetime import datetime
import requests
import random
import os
token = 'put your token here'
bot = telebot.TeleBot(token)
main_folder = 'voices'
nb_get_voice = "🎲 Get instructions!"
message_start = '👋🏻 Hello! We sing in audio messages. Sing to me in an audio message and in return I will send a random audio message with another member singing. Project news: https://t.me/steemsong Project chat: https://t.me/audioactive'
message_default = '✉️Send me an audio message!'
message_voice = 'You sent me an audio message, great!'
message_instruction = 'Hello! We sing in audio messages. \n\r\n\rSing me in an audio message and I'll send you a random audio message with another member singing in return. \n\r\n\rProject news: https://t.me/steemsong \n\rProject chat: https://t.me/audioactive \n\r'
def program_setting():
if not os.path.exists(main_folder):
os.mkdir(main_folder)
def initial_keyboard():
markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=1)
button_1 = types.KeyboardButton(nb_get_voice)
markup.add(button_1)
return markup
@bot.message_handler(commands=['start'])
def start(message):
markup = initial_keyboard()
bot.send_message(message.chat.id, message_start, reply_markup=markup)
@bot.message_handler(content_types=["text"])
def all_messages(message):
if message.text == nb_get_voice:
bot.send_message(message.chat.id, message_instruction)
else:
bot.send_message(message.chat.id, message_default)
@bot.message_handler(content_types=['voice'])
def repeat_all_message(message):
all_voices = []
files = os.listdir(main_folder)
for file in files:
if file.endswith('.ogg'):
all_voices.append(file)
with open(f'{main_folder}/{random.choice(all_voices)}', 'rb') as f:
bot.send_audio(message.chat.id, f)
#bot.send_message(message.chat.id, message_voice)
now = datetime.now().strftime("%Y%m%d%I%M")
file_info = bot.get_file(message.voice.file_id)
file = requests.get('https://api.telegram.org/file/bot{0}/{1}'.format(token, file_info.file_path))
file_presence = True
i = 0
while file_presence:
i += 1
if i == 1:
path_file = f'{main_folder}/voice({now}).ogg'
else:
path_file = f'{main_folder}/voice({now})_{str(i)}.ogg'
if not os.path.exists(path_file):
with open(path_file, 'wb') as f:
f.write(file.content)
file_presence = False
if __name__ == '__main__':
program_setting()
bot.infinity_polling()
Hello friend!
![image.png](https://steemitimages.com/640x0/https://cdn.steemitimages.com/DQmd7of2TpLGqvckkrReWahnkxMWH6eMg5upXesfsujDCnW/image.png)
![image.png](https://steemitimages.com/640x0/https://cdn.steemitimages.com/DQmWDnFh7Kcgj2gdPc5RgG9Cezc4Bapq8sQQJvrkxR8rx5z/image.png)
I'm @steem.history, who is steem witness.
Thank you for witnessvoting for me.
please click it!
(Go to https://steemit.com/~witnesses and type fbslo at the bottom of the page)