Coder Social home page Coder Social logo

pybot's Introduction

PyBot

This is my first telegram bot written in Python

Commands

/bug                - Link to create issue on github
/db <SQL query>     - Manage your database (Only for admins)
/info               - Information about this bot
/ping               - [DEPRECATED] Show usage of pinger command wich allow to
                    + add ping phrases for user who call this command
/w <City>           - Short form of /w
/weather <City>     - Weather in a city for now, today and tommorow
/wset <City>        - Set default city for /weather
/crypto             - Crypto-currency exchange rate

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
  weather_token: YOUR_TOKEN  # You can get a weather token here: http://openweathermap.org/
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
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 in your system

docker-compose up --build

How to manage database

If you want that 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 also can use the /ping command for this, and so all the others (besides the administrator) can use this to add trigers but not more than 10

If you want to summon someone with just mentioning of his name or nickname

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

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

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

There is 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

This commands setting notifications for users.
When you will send a message with a match which in ping_phrases table and with match of user, bot will reply on your message with @username in his reply and that user will get a notification even if he disabled them

Example:

> Ping CuttleRat
< @CuttleRat

Ping command is different for admins and common users

Admin
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 add and delete commands you also can use multiple usernames at once, example:

/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 match
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  

And is it! Enjoy your bot!

pybot's People

Contributors

cuttlerat avatar crownberry avatar kosc avatar nesaro avatar

Watchers

 avatar  avatar

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.