This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__all__ = ['Conexao'] | |
import psycopg2 | |
class Conexao(object): | |
def __init__(self, _host, db, _user, pwd, port): | |
self._db = psycopg2.connect(host=_host, database=db, user=_user, password=pwd, port=port) | |
def execute(self, sql=None): #execute condition in database | |
try: | |
db = self._db | |
cursor = db.cursor() | |
cursor.execute(sql) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = "Vycktor Stark" | |
""" | |
This is a simple project to run your bot on Telegram and receive requests for new events via webhook on your server | |
To be very practical, I am using the / lib flask module to create this project! | |
Where you just need to declare your bot's token and the code itself will import other things, like your host, Instructions: | |
- Declare your bot's token here; | |
- Run the script on your server; | |
- Access your host + webhookstart (example: https://mysite.com/webhookstart) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local URL = require('socket.url') | |
local json = require('cjson') | |
local http = require('resty.http') | |
local api_errors = require('api_bad_requests') | |
local BASE_URL = 'https://api.telegram.org/bot' .. os.getenv("TG_TOKEN") | |
local api = {} | |
local function getCode(err) | |
local err = err:lower() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define red_esquerdo 2 | |
#define red_direito 13 | |
#define yellow_esquerdo 3 | |
#define yellow_direito 12 | |
#define green_esquerdo 4 | |
#define green_direito 11 | |
#define botao_red 10 | |
#define botao_white 9 | |
#define postes 8 | |
void setup(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = "Vycktor Stark" | |
""" | |
This is a simple project to run a bot on the telegram via polling (webscraping) without using a module or lib | |
to start the code, after the download, just first insert your bot key to it and run as follows: `python3 main.py` | |
Note: I am aware that it is much more practical to use the / lib module to create the code faster, | |
but the goal of this snippet is to demonstrate an alternative for you to create the code your way | |
""" | |
from threading import Thread | |
import json, requests, re, time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = "Vycktor Stark" | |
""" | |
This is a simple project to execute a command on your terminal | |
using a telegram bot that will work with the telepot framework | |
To start the code, after the download, just enter your bot's token | |
and your account ID and then execute the following: `python3 main.py` | |
""" | |
import telepot, re, time, subprocess | |
bot, sudo_id = telepot.Bot('Token'), 12998399 #Set your bot's token, and your account id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = "Vycktor Stark" | |
import requests, os | |
token = os.environ['SECRET_KEY'] #Defining bot token (This information can be loaded in another way) | |
apitelegram = f"https://api.telegram.org/bot{token}" #Defining api of telegram (This information can be loaded in another way) | |
def checkchat(idchat): | |
""" | |
This function was created to analyze if the defined ID when it is called, | |
has the chat blocked for the bot or not. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = "Vycktor Stark" | |
""" | |
This function was created to analyze if the defined ID left the chat blocked for the bot; | |
if true, the bot will inform the administrator | |
""" | |
def checkchat(method="sendMessage", **args): | |
import requests, os | |
""" | |
This information below is not necessary for this function to work, | |
the information can be loaded in another way, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = "Vycktor Stark" | |
class Method(): | |
""" | |
This method will help you to manipulate the Telegram API easily, | |
because basically it will communicate with the api by sending | |
the necessary arguments without the need to write a lot of code | |
or use a Telegram Frameworks / SDK / Wrapper. | |
""" | |
def __init__(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = "Vycktor Stark" | |
import json, requests, re, time | |
SECRET_KEY = '523403928:ARxEXsjjhdosifoTm_QKPR_hy-EOcY0Qi4' # Define your bot's token | |
TELEGRAM_API = f'https://api.telegram.org/bot{SECRET_KEY}' | |
forward_chat_information = 438131290 # id to forward chat information | |
def polling(): | |
temp = 100 | |
while True: | |
data = requests.get(f"{TELEGRAM_API}/getUpdates", params=dict(offset=temp, timeout=int(temp+1), allowd_updates='message'), headers={"Content-Type": "application/json"}) |