Skip to content

Instantly share code, notes, and snippets.

View voider1's full-sized avatar

Wesley A. Gahr voider1

View GitHub Profile
import os
from functools import wraps
from sqlalchemy import create_engine, Column, Integer, String
from sqlalcheny.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
def is_admin(func):
"""Checks wether the user who issues the command is the admin.
Use this if there's supposed to be one, and only one admin."""
@voider1
voider1 / python-telegram-api-timeout-decorator.py
Last active October 30, 2016 18:33
Use this the python-telegram-bot API, this ensures there's a timeout for certain functions, just add @timeout(duration) above your function definition.
import time
from functools import wraps
timeout_funcs = {}
def get_seconds():
return int(round(time.time()))
@voider1
voider1 / python-telegram-api-is-started.py
Last active June 27, 2018 13:31
A decorator for python-telegram-bot API, makes sure a command is only executed when the bot's state is started!
from functools import wraps
from telegram.ext import Updater, CommandHandler
# Using a factory function (closures) to contain the started-state of the bot
# This is cleaner and better-practice than using globals
def state_factory():
"""Factory function for containing the bot state."""
state = False
@voider1
voider1 / python-telegram-api-before-response.py
Last active June 27, 2018 15:04
Use this Gist with the python-telegram-bot API, this is a decorator which executes a function before anything else is done.
from functools import wraps
from telegram import ChatAction
def before_response(function):
"""Do something before responding"""
def do_before(func):
@wraps(func)