Skip to content

Instantly share code, notes, and snippets.

View 4Kaylum's full-sized avatar

Kae Bartlett 4Kaylum

View GitHub Profile
@4Kaylum
4Kaylum / mee6_rank.py
Created September 6, 2019 22:24
A cog that gets a person at rank N on the Mee6 leaderboards
"""Gets a member at the Nth place on Mee6's leaderboard"""
from discord.ext import commands
from cogs import utils
class Mee6Ranking(utils.Cog):
def __init__(self, bot:utils.CustomBot):
@4Kaylum
4Kaylum / colours.py
Last active September 26, 2020 20:45
COLOURS = {
"caleb blue": 0x5dadec,
"ollie yellow": 0xf5e59d,
"poop brown": 0x7a5901,
"stegosans": 0xf1e6a9,
"teddy purple": 0xb19cd9,
# Below this point is directly copied from the Github link,
# minus a bunch that were repeated colours later
"alice blue": 0xf0f8ff,
from requests import get
def get_dog(*, dog_id:str='', limit:int=1) -> dict:
url = 'https://api.thedogapi.co.uk/v2/dog.php'
params = {}
if dog_id:
params.update({'id': dog_id})
if limit > 1:
params.update({'limit': limit})
site = get(url, params=params)
from random import shuffle
class Card(object):
'''
A card object - represents a card from the deck
'''
def __init__(self, value, suit):
self.value = value
@4Kaylum
4Kaylum / provablyfair.py
Last active March 4, 2022 02:16
Implementation of the Primedice provably fair algorithm (https://dicesites.com/primedice/verifier)
import random
import secrets
import hashlib
import hmac
class ProvablyFair(random.Random):
"""An object that represents a provably fair algorithm"""
def __init__(self, client_seed:str=None, *, server_seed:str=None):
@4Kaylum
4Kaylum / DiscordPy Tutorial.md
Last active January 14, 2025 04:37
A simple bot tutorial for Discord.py

Writing a Discord bot with Discord.py

Hey one, hey all, and welcome to a basic Discord bot writing tutorial. This is a basic tutorial that doesn't cover coding in general, but rather how to work with the Discord.py (v1.0.0a) library and how to write a simple bot with it. General help can be found on the Discord API guild and in the documentation.

This tutorial assumes some prior knowledge of programming, and assumes you already have Python3.5 (and Pip) or later installed and added to your PATH.

With that, let's get to it.

Installation

from json import load, dump
from random import choice
class JsonDB(object):
'''
An object to handle the quotes database for you
Parameters:
filename: str
class Node(object):
def __init__(self, program):
self.raw = program
x = program.split(' ')
# name, weight (->, program, program..)
self.parent = None
self.name = x[0]
self.weight = int(x[1][1:-1])
self.children = ' '.join(x[3:]).split(', ')
self.children_objs = []
def validate_passphrase(passphrases:str) -> int:
'''
Counts the number of valid passphrases
'''
passphrases = [[item for item in row.split(' ')] for row in passphrases.split('\n')]
valid = 0
for row in passphrases:
counter = 0
for item in row:
def get_checksum(spreadhseet:str) -> int:
spreadhseet = [[int(val) for val in row.split('\t') if val] for row in spreadhseet.split('\n')]
val = 0
for row in spreadhseet:
val += max(row) - min(row)
return val
def get_checksum_part_2(spreadhseet:str) -> int:
spreadhseet = [[int(val) for val in row.split('\t') if val] for row in spreadhseet.split('\n')]