Skip to content

Instantly share code, notes, and snippets.

View VycktorStark's full-sized avatar
🤖

Vycktor VycktorStark

🤖
View GitHub Profile
@VycktorStark
VycktorStark / Notifyactionsbot.py
Created August 13, 2020 15:30
Notify actions for when a user joins or leaves the group
__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"})
@VycktorStark
VycktorStark / handler-botapi.py
Last active July 4, 2020 00:09
This method will help you to manipulate the Telegram API easily
__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):
@VycktorStark
VycktorStark / checkchatexecute.py
Last active June 29, 2020 21:01
An example of a function created to analyze whether the defined ID left the chat blocked for the bot; if true, the bot will inform the administrator
__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,
@VycktorStark
VycktorStark / checkchat.py
Last active June 29, 2020 20:56
An example function to analyze if the ID defined in it, left the chat blocked for the bot to send new messages.
__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.
@VycktorStark
VycktorStark / main.py
Last active July 23, 2020 00:18
This project aims to execute functions in the terminal using the bot, it was developed in python with one using the telepot framework.
__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
@VycktorStark
VycktorStark / main.py
Last active August 13, 2020 15:28
Simple bot with polling - TELEGRAM BOT
__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
@VycktorStark
VycktorStark / Sema2cruzamento.ino
Created June 8, 2020 18:51
Cruzamento de 2 semafaro
#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(){
@VycktorStark
VycktorStark / telegrambotapi.lua
Created June 8, 2020 18:47
Telegram-bot-api in lua
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()
@VycktorStark
VycktorStark / main.py
Last active June 15, 2020 10:26
Simple bot with webhook - TELEGRAM BOT
__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)
@VycktorStark
VycktorStark / database.py
Last active April 4, 2020 19:08
Database using psycopg2
__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)