TEN POINTS TO GRYFFINDORgit pull
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
import asyncio
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from pprint import pprint
|
||||
import time
|
||||
import numpy as np
|
||||
import random
|
||||
|
||||
class Points(object):
|
||||
"""Geef elkaar punten!"""
|
||||
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.voice_states = {}
|
||||
|
||||
#a = discord.get_channel(self.bot.hdChannels["shitpost"])
|
||||
#pprint(a)
|
||||
|
||||
def __check(self, ctx):
|
||||
return True
|
||||
|
||||
@commands.command(pass_context=True, hidden=False)
|
||||
@asyncio.coroutine
|
||||
def geefpunten(self, ctx, user, points: int):
|
||||
"""Wees eens lief. Geef iemand wat punten.
|
||||
Bijvoorbeeld:
|
||||
!geefpunten @ikbenjp 42
|
||||
Let op: je moet iemand taggen om punten uit te delen
|
||||
"""
|
||||
|
||||
if points == 0:
|
||||
yield from ctx.channel.send("0 punten? Gul hoor.")
|
||||
return
|
||||
if points < 0:
|
||||
yield from ctx.channel.send("Doeslief. Je mag (nog) geen punten afnemen.")
|
||||
return
|
||||
|
||||
if user[0:2] != "<@":
|
||||
try:
|
||||
yield from ctx.message.delete()
|
||||
yield from ctx.message.author.send("Je moet iemand taggen om punten te geven. :)")
|
||||
#TODO ook userId oid toestaan?
|
||||
except:
|
||||
print("No permission to delete message or send DM")
|
||||
return
|
||||
|
||||
userObj = self.bot.get_user( int(user.replace("<@", "").replace(">", "")) )
|
||||
|
||||
if not self.isUserOnList(userObj):
|
||||
yield from ctx.channel.send("Nee. Die krijgt geen punten.")
|
||||
return
|
||||
if self.getUserBalance(ctx.author) < points:
|
||||
yield from ctx.channel.send("Daar heb jij niet genoeg puntjes voor. :bell:")
|
||||
return
|
||||
|
||||
self.transferPoints(ctx.author, userObj, points)
|
||||
|
||||
message = self.getMessageForAwardingPoints(ctx.author.name, userObj.name, points)
|
||||
yield from ctx.channel.send(message)
|
||||
|
||||
|
||||
@commands.command(pass_context=True, hidden=False)
|
||||
@asyncio.coroutine
|
||||
def puntentelling(self, ctx):
|
||||
"""Hoeveel punten heeft iedereen?
|
||||
"""
|
||||
|
||||
#TODO format
|
||||
#TODO sort
|
||||
message = "De puntentelling: \n"
|
||||
pointsCount = np.load('pointscount.npy').item()
|
||||
for user in pointsCount:
|
||||
message += str(pointsCount[user]["points"]) + " " + pointsCount[user]["name"] + "\n"
|
||||
yield from ctx.channel.send(message)
|
||||
|
||||
|
||||
# Transfer points form one user to another
|
||||
def transferPoints(self, fromUser, toUser, points):
|
||||
pointsCount = np.load('pointscount.npy').item()
|
||||
pointsCount[fromUser.id]["points"] -= points
|
||||
pointsCount[toUser.id]["points"] += points
|
||||
np.save("pointscount.npy", pointsCount)
|
||||
print(pointsCount)
|
||||
|
||||
# Do we know this user?
|
||||
def isUserOnList(self, user):
|
||||
pointsCount = np.load('pointscount.npy').item()
|
||||
return user.id in pointsCount.keys()
|
||||
|
||||
# Get a user's point balance
|
||||
def getUserBalance(self, user):
|
||||
pointsCount = np.load('pointscount.npy').item()
|
||||
return pointsCount[user.id]["points"]
|
||||
|
||||
# Generate a semi-random text to tell somebody they got some shiny new points
|
||||
def getMessageForAwardingPoints(self, userNameFrom: str, userNameTo: str, points: int):
|
||||
p = str(points)
|
||||
messages = [
|
||||
p + " punten voor " + userNameTo + ".",
|
||||
userNameTo + " krijgt " + p + " punten.",
|
||||
userNameTo + " krijgt " + p + " punten van " + userNameFrom,
|
||||
p + " POINTS TO GRYFFINDO.. oh.. " + userNameTo + ".",
|
||||
userNameTo + ", jij krijgt " + p + " puntjes van " + userNameFrom + ". Lief he? :heart:",
|
||||
"+" + p + " punten voor " + userNameTo + "! Highscore!",
|
||||
userNameTo + ", alsjeblieft, " + p + " punten.",
|
||||
"Hier zijn " + p + " punten, " + userNameTo + ". Don't spend it all in one place...",
|
||||
"Jij kan wel " + p + " punten gebruiken, " + userNameTo + ".",
|
||||
p + " blockchain smartcontract punten voor " + userNameTo + ". :rocket: "
|
||||
]
|
||||
return messages[random.randint(0, len(messages)-1)]
|
||||
|
||||
|
||||
def init(self):
|
||||
# Check if points file exists:
|
||||
try:
|
||||
pointsCount = np.load('pointscount.npy').item()
|
||||
except FileNotFoundError:
|
||||
np.save("pointscount.npy", {})
|
||||
pointsCount = np.load('pointscount.npy').item()
|
||||
|
||||
memberList = self.bot.get_channel(self.bot.hdChannels["shitpost"]).members
|
||||
for member in memberList:
|
||||
# Give new members 100 points
|
||||
if member.id not in pointsCount.keys() and not member.bot:
|
||||
pointsCount[member.id] = {"name": member.name, "points": 100}
|
||||
np.save("pointscount.npy", pointsCount)
|
||||
Reference in New Issue
Block a user