Python Template For Gomaneshgar's Bot Written in Python 3 .
First of all install Python >= 3.5 and then install pip3
.
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python3.5
sudo apt-get install python3-pip
OR Compile with Source:
wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz
tar xfz Python-3.5.*
cd Python-3.5.*
./configure --with-ensurepip=install
make
sudo make install
Run These commands for Resolving the dependencies.
sudo pip3 install pip -U
sudo pip3 install telepot -U
sudo pip3 install demjson
Open config.json then add Group, Token and The bot's Username.After that just run this command to run!
python3 bot.py
This bot is plugins based so you can add a lot of plugins in plugins folder. The plugins structure are shown below.
import asyncio
from message import Message
@asyncio.coroutine
def run(message, matches, chat_id, step):
return Message(chat_id).set_text("The Championship is started.")
plugin = {
"name": "start",
"run": run,
"patterns": ["^آغاز$"]
}
This is start plugin and each plugin has some values in a dictionary with plugin name:
name --> plugin name
patterns --> some regex in a list to fire this plugin to run ...
Inside run function do everything do you want and then if you want to send message just return this object :
return Message(chat_id).set_text("Sample Text")
This file contains 4 function that Your AI should implement there :
choose_question --> Will ask question when your turn up ...
make_guess --> Will Find a guess ...
has_any_point_for_direct --> if it is true, it will ask a Direct Question with make_guess() return Value else it will ask from choose_question()
has_any_point_for_vanahesht --> if it is true, it will send Vanahesht message with make_guess()
If you want to answer, you can use vanahesht("ANSWER")
function in bot.py.
In plugins/guess.py
there is a function and its name is make_guess
. Complete this function and it will send the return value when حدس
message send or after the twenieth question.
Your AI can work in other threads (For calculating a new question or sending Vanahesht). If you want Send Message whenever you want just send it into sender_queue :
sender_queue.put(Message(config['group']).set_text("TEST")
Just rename aifunctions-sample.py
to aifunctions.py
to Test it.
It choose a random question and answer and for question number 101 ask a direct question and for question number 999 message a vanahesht.
There is a history variable in bot.py that stores all questions with their answer from another bots.
Please feel free to ask any questions here by issues or on telegram via @Siyanew