Sfoglia il codice sorgente

!registration

tags/v0.1^2
Ben Kurtovic 13 anni fa
parent
commit
4488f6f5e3
1 ha cambiato i file con 63 aggiunte e 0 eliminazioni
  1. +63
    -0
      bot/commands/registration.py

+ 63
- 0
bot/commands/registration.py Vedi File

@@ -0,0 +1,63 @@
# -*- coding: utf-8 -*-

import time

from classes import BaseCommand
import wiki

class Command(BaseCommand):
"""Return when a user registered."""
name = "registration"

def check(self, data):
commands = ["registration", "age"]
if data.is_command and data.command in commands:
return True
return False

def process(self, data):
if not data.args:
name = data.nick
else:
name = ' '.join(data.args)

site = wiki.get_site()
site._maxlag = None
user = site.get_user(name)

try:
reg = user.registration()
except wiki.UserNotFoundError:
msg = "the user \x0302{0}\x0301 does not exist."
self.connection.reply(data, msg.format(name))
return

date = time.strftime("%b %m, %Y at %I:%M:%S %p", reg)
age = self.get_diff(time.mktime(reg), time.mktime(time.gmtime()))

g = user.gender()
if g == "male":
gender = "He's"
elif g == "female":
gender = "She's"
else:
gende = "They're"
msg = "\x0302{0}\x0301 registered on {1}. {2} {3} old."
self.connection.reply(data, msg.format(name, date, gender, age))

def get_diff(self, t1, t2):
parts = {"years": 31536000, "days": 86400, "hours": 3600,
"minutes": 60, "seconds": 1}
msg = []

order = sorted(parts.items(), key=lambda x: x[1], reverse=True)
for key, value in order:
num = 0
while t2 - t1 > value:
t1 += value
num += 1
if num or (not num and msg):
msg.append(" ".join((str(num), key)))

return ", ".join(msg)

Caricamento…
Annulla
Salva