Coder Social home page Coder Social logo

yoba's Introduction

YOBA

Yet One Bot Assistant - just a funny telegeram bot.

CircleCI

Commands

/issue                     - Link to create an issue on github
/bug                       - The same as /issue
/db <SQL query>            - Manage your database (Only for admins)
/info                      - Information about this bot
/ping_add [matches]        - Add casts for users. Admins can use it like this
                           + /ping_add @username1 @username2 match1 match2
/ping_add_me               - Add casts for user which can be randomly chosen in /me command
/ping_show                 - Show all casts for user
/ping_show_all             - Show all casts from DB for this chat (only for admins)
/ping_delete [matches]     - Delete matches for user. The same usage for admins as for /ping_add
/ping_delete_me            - Delete matches for user which can be used in /me
/ping_drop <Username>      - Delete all matches for user (only for admins)
/me [message]              - Delete source message and replace it with this one
                           + <Random cast for user which was added by /ping_add_me> [message]
/clash                     - Create a CoC competition (https://condingame.com)
/clash_start               - Start a CoC competition
/clash_enable              - Enable CoC notifications
/clash_disable             - Disable CoC notifications
/clash_results <clash_id>  - CoC results of a given <clash_id> game,
                           + or the last one if called without any args

Starting

git clone https://github.com/Cuttlerat/pybot.git
cd pybot

Add your telegram username, tokens, and database path into ./bot/config/config.yaml file

tokens:
  tg_token: YOUR_TOKEN       # Register your bot here: https://t.me/BotFather
clash:
  login: YOUR_codingame.com_LOGIN
  password: YOUR_codingame.com_PASSWORD
redis:
  host: redis
  port: 6379
telegram:
  mode: Polling # or Webhook
  webhook_port: 30222
  webhook_url: https://example.com/{}
  # Use this if you want to run with webhook not in docker
  listen_ip: 0.0.0.0 # Your IP
database:
  host: data/pybot.db
log:
  level: INFO               # Can be one of ["DEBUG", "INFO", "WARN", "ERROR", "CRITICAL"]
admins:
  - Username1
  - Username2

Then just launch the bot

./bot/main.py

Starting into a docker container

In order to build and create a docker container, docker-compose must be installed on your system

docker-compose up --build

How to manage database

If you want your bot triggers on a some type of messages, there some options here.

Simple trigger

If you want a simple trigger on a message responding with your specified string

/db INSERT INTO answers(match,string) VALUES("hello!", "Hi!")
Cuttlerat: Hello!
Cutltebot: Hi!

Ping

Add it into database

You can also use the /ping command for this, others (besides admins) can use it to add trigers by themselves, but not more than 10 per user.

If you want to summon someone by mentioning his name or nickname

/db INSERT INTO pingers(username,match) VALUES("Cuttlerat", "rat")
Cuttlerat: rat!
*nothing*

Why it didn't work? Because we haven't set a ping phrase yet

/db INSERT INTO ping_phrases(phrase) VALUES("ping")
Cuttlerat: ping rat
Cuttlebot: @Cuttlerat

There is also a little trick to summon all persons from the pingers table

/db INSERT INTO pingers(username,match) VALUES("hotkosc", "kosc")
/db INSERT INTO pingers(username,match) VALUES("EVERYONE GET IN HERE", "all")
Cuttlerat: ping all
Cuttlebot: @Cuttlerat @hotkosc

But what if you want to call everyone except one guy?

You will need to add a ping exclude phrase

/db INSERT INTO ping_exclude(match) VALUES("except")
Cuttlerat: ping all except kosc
Cuttlebot: @Cuttlerat

Add with /ping_* commands

/ping command is deprecated! Use /ping_add, /ping_show, /ping_show_all and /ping_delete instead

These commands set and delete ping phrases for users and show them the existing ones. When you send a message with a match from ping_phrases table and with a match that user sets, bot will reply on your message with his @username in and that user will get a notification even if he disabled them for this chat.

Example:

> Ping CuttleRat
< @CuttleRat

Ping command is different for admins and common users

Admins usage
Usage:
/ping_add [@username] [match] - Add a ping for @username with match
/ping_show [@username] - Show all matches of this user in this chat
/ping_show_all - Show all mathces for all users in this chat
/ping_delete [@username] [match] - Delete a match for this user if it exists
/ping_drop [@username]` - Delete all matches for this user if it exists

For /ping_add and /ping_delete commands you can also use multiple usernames at once

/ping_add @user_1 @user_2 @user_3 match
/ping_delete @user_1 @user_2 @user_3 match
/ping_drop @user_1 @user_2 @user_3
Common user
Usage:
/ping_add [match] - Add a match for you. You can have only 10 matches, or more if an administrator will add it for you
/ping_show [@username] - Show all matches for @user_1
/ping_delete [match] - Delete a match

Clash of code

The following commands allow you to create a new Clash of Code game and not miss any games created by someone else.

Create a new game

/clash

Cuttlebot:

Clash of Code!

https://www.codingame.com/clashofcode/clash/GAME_ID

@User1 @User2 @User3

Please send /clash_disable if you don't want to receive these notifications

Disable and enable notifications

/clash_disable

Cutlebot:

Now you won't receive any notifications about Clash of Code games
/clash_enable

Cutlebot:

You will be notified when a new game is created!

Manually start the last created game

Remember that only the creator can start the game.

/clash_start

Cuttlebot:

The game is about to start, hurry up!

@User1 @User2 @User3

Get game results

/clash_results <game_id>

Game id: <game_id>
Game mode: Shortest
Status: Finished

╒════╤═══════════╤═════════╤═════════╤══════════════╕
│    │ Username  │ Score   │ Time    │   Characters │
╞════╪═══════════╪═════════╪═════════╪══════════════╡
│  1 │ User1     │ 100%    │ 0:01:00 │           87 │
├────┼───────────┼─────────┼─────────┼──────────────┤
│  2 │ User2     │ 100%    │ 0:05:00 │          107 │
╘════╧═══════════╧═════════╧═════════╧══════════════╛

Enjoy your bot!

yoba's People

Contributors

crownberry avatar cuttlerat avatar kosc avatar nesaro avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

yoba's Issues

Add commands for chatquotes

/chatquotes - Random quote from chatquotes
[Forwarded messages to bot]
/chatquotes - Add quote only if user who send it in chatquote admins
/chatquotes [ID] - Send quote with this ID

If you can suggest a new command please leave a comment with a description of it and an example of use

Exception when message is empty in /me

yoba_1  | 2019-05-13 13:12:04,266 - telegram.ext.dispatcher - ERROR - An uncaught error was raised while processing the update
yoba_1  | Traceback (most recent call last):
yoba_1  |   File "/usr/local/lib/python3.6/site-packages/telegram/ext/dispatcher.py", line 279, in process_update
yoba_1  |     handler.handle_update(update, self)
yoba_1  |   File "/usr/local/lib/python3.6/site-packages/telegram/ext/commandhandler.py", line 173, in handle_update
yoba_1  |     return self.callback(dispatcher.bot, update, **optional_args)
yoba_1  |   File "main.py", line 41, in new_action
yoba_1  |     action(input_config, bot, update, **kwargs)
yoba_1  |   File "/yoba/handlers/me.py", line 26, in me
yoba_1  |     message=update.message.text.split(' ', 1)[1]))
yoba_1  | IndexError: list index out of range

Sqlite3 spam in logs

Sqlite3 spam in logs should be fixed

Example:

yoba_1  | During handling of the above exception, another exception occurred:
yoba_1  |
yoba_1  | Traceback (most recent call last):
yoba_1  |   File "/usr/local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 300, in _close_connection
yoba_1  |     self._dialect.do_close(connection)
yoba_1  |   File "/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 446, in do_close
yoba_1  |     dbapi_connection.close()
yoba_1  | sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread

Change log format to json

Change log format to json like this

{
"message": "Start",
"command": "start",
"user": "@username/user_id",
"timestamp": "2000-01-01T00:00:00Z"
}

Don't ping everyone if there is one pinged

We've got situations like this:

ping someuser, how can we get all credentials of our databases?
[bot pings everyone because there is "ping" and "all"]

I think, we should ignore "all" pings if there is some user already casted.

Refactoring

This project need in refactoring.
I think we should start from writing tests, but any suggestions are welcome.

Fix bug with lack of wind

Given city ​​don't have wind
When user write /weather@sticky_yoba_bot
Then Yoba can not write weather information

Clash of Code results

If it's possible to collect results when a game finishes, implement this:

/clash_results
-> Results of the last game
/clash_results GAME_ID
-> Results of the GAME_ID game

Refactor pinger function

Function for cast users looks very ugly, I think it's time to refactoring or even write this function from scratch.

Tests are not working

Need to check what's wrong with tests and fix it
Ensure that it's possible to run tests from docker to add them as a CI step

Change formatting for crypto command

Current float formatting:

1 BTC = $5329.9

Must be:

1 BTC = $5329.90

You can try this:

>>> l = 5329.9
>>> l
5329.9
>>> print("%.2f" % l)
5329.90

Implement CI

Implement CI on Travis.CI, it should build a Docker image, run tests and if all tests pass, push the image to Docker hub (or maybe to GitHub registry).

Add reaction for /me command

Example of use:

username: /me is suffering
pybot: usercast is suffering

Where usercast is random ping phrase of user @username except group casts.

Improve log level

Implement log level by in a config file. Suppress logs lower than set in the config.
Implement levels in bold.
DEGUB -> INFO -> WARN -> ERROR -> CRITICAL
All levels should be static and won't allow any other levels into logger.py

Change clash results output to image

A table from /clash_results looks too ugly on devices with a small width resolution, would be better to send results in an image instead of text

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.