Remove dead code: credits
This commit is contained in:
parent
94a9a9a30b
commit
85981b4d99
43
credits.py
43
credits.py
@ -1,43 +0,0 @@
|
|||||||
# coding=utf-8
|
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
from datetime import timedelta
|
|
||||||
import random
|
|
||||||
|
|
||||||
BANLIST = []
|
|
||||||
|
|
||||||
class Credits:
|
|
||||||
def __init__ (self, name):
|
|
||||||
self.name = name
|
|
||||||
self.credits = 5
|
|
||||||
self.randsec = timedelta(seconds=random.randint(0, 55))
|
|
||||||
self.lastmessage = datetime.now() + self.randsec
|
|
||||||
self.iask = True
|
|
||||||
|
|
||||||
def ask(self):
|
|
||||||
if self.name in BANLIST:
|
|
||||||
return False
|
|
||||||
|
|
||||||
now = datetime.now() + self.randsec
|
|
||||||
if self.lastmessage.minute == now.minute and (self.lastmessage.second == now.second or self.lastmessage.second == now.second - 1):
|
|
||||||
print("\033[1;36mAUTOBAN\033[0m %s: too low time between messages" % self.name)
|
|
||||||
#BANLIST.append(self.name)
|
|
||||||
self.credits -= self.credits / 2 #Une alternative
|
|
||||||
return False
|
|
||||||
|
|
||||||
self.iask = True
|
|
||||||
return self.credits > 0 or self.lastmessage.minute != now.minute
|
|
||||||
|
|
||||||
def speak(self):
|
|
||||||
if self.iask:
|
|
||||||
self.iask = False
|
|
||||||
now = datetime.now() + self.randsec
|
|
||||||
if self.lastmessage.minute != now.minute:
|
|
||||||
self.credits = min (15, self.credits + 5)
|
|
||||||
self.lastmessage = now
|
|
||||||
|
|
||||||
self.credits -= 1
|
|
||||||
return self.credits > -3
|
|
||||||
|
|
||||||
def to_string(self):
|
|
||||||
print ("%s: %d ; reset: %d" % (self.name, self.credits, self.randsec.seconds))
|
|
27
message.py
27
message.py
@ -21,25 +21,11 @@ import re
|
|||||||
import shlex
|
import shlex
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import credits
|
|
||||||
from credits import Credits
|
|
||||||
from response import Response
|
from response import Response
|
||||||
import xmlparser
|
import xmlparser
|
||||||
|
|
||||||
CREDITS = {}
|
|
||||||
filename = ""
|
filename = ""
|
||||||
|
|
||||||
def load(config_file):
|
|
||||||
global CREDITS, filename
|
|
||||||
CREDITS = dict ()
|
|
||||||
filename = config_file
|
|
||||||
credits.BANLIST = xmlparser.parse_file(filename)
|
|
||||||
|
|
||||||
def save():
|
|
||||||
global filename
|
|
||||||
credits.BANLIST.save(filename)
|
|
||||||
|
|
||||||
|
|
||||||
class Message:
|
class Message:
|
||||||
def __init__ (self, line, timestamp, private=False):
|
def __init__ (self, line, timestamp, private=False):
|
||||||
self.raw = line
|
self.raw = line
|
||||||
@ -133,19 +119,6 @@ class Message:
|
|||||||
#TODO: use encoding from config file
|
#TODO: use encoding from config file
|
||||||
self.content = self.content.decode('utf-8', 'replace')
|
self.content = self.content.decode('utf-8', 'replace')
|
||||||
|
|
||||||
def authorize_DEPRECATED(self):
|
|
||||||
"""Is nemubot listening for the sender on this channel?"""
|
|
||||||
# TODO: deprecated
|
|
||||||
if self.srv.isDCC(self.sender):
|
|
||||||
return True
|
|
||||||
elif self.realname not in CREDITS:
|
|
||||||
CREDITS[self.realname] = Credits(self.realname)
|
|
||||||
elif self.content[0] == '`':
|
|
||||||
return True
|
|
||||||
elif not CREDITS[self.realname].ask():
|
|
||||||
return False
|
|
||||||
return self.srv.accepted_channel(self.channel)
|
|
||||||
|
|
||||||
##############################
|
##############################
|
||||||
# #
|
# #
|
||||||
# Extraction/Format text #
|
# Extraction/Format text #
|
||||||
|
Loading…
x
Reference in New Issue
Block a user