Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris nonchris

View GitHub Profile
@nonchris
nonchris / telegram-dialogue.py
Created Nov 28, 2020
Telegram Bot Dialogue Keyboard (minimal example)
View telegram-dialogue.py
"""
This code shows how to create a custom keyboard for a telegram bot
Using https://github.com/python-telegram-bot/python-telegram-bot
"""
rom telegram.ext import Updater
from telegram.ext import CommandHandler
from telegram.ext import MessageHandler, Filters
from telegram import Bot
from telegram import KeyboardButton
from telegram import ReplyKeyboardMarkup
@nonchris
nonchris / converter.py
Created Nov 7, 2020
symbol replacer for file content
View converter.py
def conv(file: str, new="converted-file.txt", symbol=",", rep=".") -> str:
"""
Needs: filename
Optional: filename, symbol to replace, symbol to replace with
- reads data, replaces a symbol with an other symbol of choice
- writes new data in file and returns filename
"""
with open(file, "r") as f: #open file
read = f.read() #read content
repl = read.replace(symbol, rep) #replace symbol
@nonchris
nonchris / example-cog-usage.py
Last active Sep 22, 2020
Discord.py: Get Role by Role Name, ID or mention
View example-cog-usage.py
import re
import discord
"""
A function that returns the matching role-id(s) in a list (as integers)
Needed Arguments: Comamnd-Context and Role-ID/ Role-Mention/ Role-Name (as a string)
The function will return a tuple of values that contains two values:
- A list with all matching role-id (should be one most of the times)
- The length of that list as secondary return value
@nonchris
nonchris / discord-custom-help-command.py
Last active Jan 20, 2021
A kinda advanced custom "help" command for your Discord.py bots!
View discord-custom-help-command.py
import discord
from discord.ext import commands
from discord.errors import Forbidden
"""This custom help command is a perfect replacement for the default one on any Discord Bot written in Discord.py!
However, you must put "bot.remove_command('help')" in your bot, and the command must be in a cog for it to work.
Original concept by Jared Newsom (AKA Jared M.F.)
[Deleted] https://gist.github.com/StudioMFTechnologies/ad41bfd32b2379ccffe90b0e34128b8b
Rewritten and optimized by github.com/nonchris
You can’t perform that action at this time.