Skip to content

Commit

Permalink
Migration to python 3
Browse files Browse the repository at this point in the history
Migrated to python 3 using 2to3 and many manual fixes.
This is currently still experimental and the plugins need to be tested
and adapted when something is not working as before.
  • Loading branch information
allo- committed Nov 30, 2020
1 parent 8e7a9af commit e145de0
Show file tree
Hide file tree
Showing 52 changed files with 362 additions and 344 deletions.
68 changes: 34 additions & 34 deletions contrib/plugins/ircClient/nip.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from otfbot.lib import functions
from otfbot.lib.pluginSupport.decorators import callback
import twisted.internet.task as timehook # ugh
import shutil, time, random, string, os
import shutil, time, random, os
import math, pickle, atexit
import operator

Expand Down Expand Up @@ -123,7 +123,7 @@ def findex(self, oldlist, favoritee):
def add(self, player, favoritee):
if player==favoritee:
return False
if self.favdict.has_key(player):
if player in self.favdict:
favoritees=self.favdict.get(player,"[]")
findex=self.findex(favoritees, favoritee)
if findex > -1:
Expand All @@ -137,7 +137,7 @@ def add(self, player, favoritee):
self.favdict[player]=[[favoritee,1],]

def getlist(self, player):
if self.favdict.has_key(player):
if player in self.favdict:
return sorted(self.favdict.get(player,"[]"),key=operator.itemgetter(1),reverse=True)
else:
return False
Expand All @@ -147,7 +147,7 @@ def save(self, favfile):
pickle.dump(self.favdict,sfile)
sfile.close()
except IOError:
print "Error writing to file "+favfile+"(check permission)"
print("Error writing to file "+favfile+"(check permission)")
finally:
sfile.close()
pass
Expand All @@ -158,7 +158,7 @@ def load(self, favfile):
self.favdict=pickle.load(lfile)
lfile.close()
except IOError:
print "Cannot read "+favfile+"(will be created)"
print("Cannot read "+favfile+"(will be created)")
finally:
pass
def clear(self, acthof): #will remove any "favoritee" in fav.dict if not found in "HoF"
Expand All @@ -169,7 +169,7 @@ def clear(self, acthof): #will remove any "favoritee" in fav.dict if not found i
for players in acthof:
isin.append(players[0]) #all players in hof

for playername,favlist in self.favdict.iteritems():
for playername,favlist in self.favdict.items():
li=0
for fav, val in favlist:
if fav not in isin:
Expand Down Expand Up @@ -209,9 +209,9 @@ def save(self, nipbufferfile):
sfile=open(nipbufferfile+".dat", "w")
for player in self.question:
player=str(player)
if self.question.has_key(player) and self.answer.has_key(player):
if player in self.question and player in self.answer:
tip=""
if self.tip.has_key(player):
if player in self.tip:
tip=self.tip[player]
sfile.write(player+"#"+str(self.question[player])+"#"+str(self.answer[player])+"#"+tip+"\n")
sfile.close()
Expand Down Expand Up @@ -560,11 +560,11 @@ def nipmsg(self, cmsg, ochannel=None):
cchannel=self.GAMECHANNEL
else:
cchannel=ochannel
for color in self.colors.keys():
for color in list(self.colors.keys()):
if cmsg.count(color):
val=self.colors.get(color, "")
cmsg = cmsg.replace(color,val)
for pre in self.pres.keys():
for pre in list(self.pres.keys()):
if cmsg.count(pre):
val=self.pres.get(pre, "")
cmsg = cmsg.replace(pre, val)
Expand Down Expand Up @@ -748,7 +748,7 @@ def del_player(self, delnick, refby=None): #refby=call other subroutines or not
c=1
self.gamemaster=""
if not refby=="end_of_quiz": #avoids double msg while autoremove gamemaster as gameadmin
if not self.answers.has_key(delnick): #avoids eog while gamemaster had sent in question AND answer
if delnick not in self.answers: #avoids eog while gamemaster had sent in question AND answer
self.end_of_quiz()

if c: #changed
Expand Down Expand Up @@ -794,7 +794,7 @@ def warn_players(self):
wplayers=wplayers+" "+player
if self.phase==WAITING_FOR_ANSWERS:
for player in self.players:
if not player in self.answers.keys():
if not player in list(self.answers.keys()):
wplayers=wplayers+" "+player
if self.phase==WAITING_FOR_QUESTION: # or self.phase==WAITING_FOR_QUIZMASTER_ANSWER:
wplayers=str(self.gamemaster)
Expand Down Expand Up @@ -839,7 +839,7 @@ def end_of_answertime(self):

self.nipmsg("PRE_G#UNDERLINE#Mögliche #BOLD#Antworten#BOLD# sind:#UNDERLINE# ".decode(self.NIPencoding)+" (#DRED#Aufforderung abwarten!#DRED#)")

users=self.answers.keys()
users=list(self.answers.keys())
random.shuffle(users)
for user in users:
self.nipmsg("PRE_C#BOLD#"+str(count)+"#BOLD#. "+self.answers[user])
Expand All @@ -853,13 +853,13 @@ def add_allscore(self, player, qty=None):
#just send negative values for qty if you want to "punish" a player
# if qty is 0 self.score[user] will be used to calc gameround points
if qty!=None:
if str(player) in self.allscore.keys():
if str(player) in list(self.allscore.keys()):
self.allscore[player]+=qty
else:
self.allscore[player]=qty
else: #round "allscore" calculation
if str(player) in self.answeruser.values(): #we are evil at that point - no point for no given answer
if player in self.allscore.keys():
if str(player) in list(self.answeruser.values()): #we are evil at that point - no point for no given answer
if player in list(self.allscore.keys()):
self.allscore[player]+=self.score[player]
else:
self.allscore[player]=self.score[player]
Expand Down Expand Up @@ -899,7 +899,7 @@ def quiz_scoring(self):
if self.splitpoints: #show only if wanted scoreS(splitted) not score ;)
pscores="#DGREY#("+self.scores[player]+")#NORM#" #maybe good to use in add_allscore with eval() - later

if str(player) in self.answeruser.values(): #we are !evil, no points for no given nip answer but guessing ;)
if str(player) in list(self.answeruser.values()): #we are !evil, no points for no given nip answer but guessing ;)
self.nipmsg("PRE_S"+player+" bekommt #BOLD#"+str(pscore)+"#BOLD##NORM# "+pword+" "+pscores)
else:
self.nipmsg("PRE_P"+player+" #UNDERLINE#bekäme#UNDERLINE##BOLD# ".decode(self.NIPencoding)+str(pscore)+"#BOLD##NORM# "+pword+"#DGREY# (Keine mögl. Antwort geliefert, keine Pünktchen!)".decode(self.NIPencoding))
Expand All @@ -912,13 +912,13 @@ def quiz_scoring(self):

def check_for_answer(self):
for player in self.players:
if not player in self.answeruser.values():
if self.userWarnCnt.has_key(player):
if not player in list(self.answeruser.values()):
if player in self.userWarnCnt:
self.userWarnCnt[player]+=1
else:
self.userWarnCnt[player]=1
else:
if self.userWarnCnt.has_key(player):
if player in self.userWarnCnt:
self.userWarnCnt[player]=0


Expand All @@ -934,7 +934,7 @@ def autoremoving(self, justplayer=None):
else:
#self.bot.logger.debug("autoremoving player")
for player in self.players:
if player in self.userWarnCnt.keys():
if player in list(self.userWarnCnt.keys()):
if int(self.userWarnCnt.get(player,0))>=self.userWarnMax:
self.del_player(player,"autoremoving")

Expand All @@ -956,7 +956,7 @@ def no_nip_question(self):
gmaster=self.gamemasterold #maybe he has "removed"
if self.gamemaster!="":
gmaster=self.gamemaster
if not self.answers.has_key(gmaster):
if gmaster not in self.answers:
return "PRE_X"+self.TGAMEMASTER+" "+gmaster+" hatte keine "+self.TNIPQUESTION

def add_new_players(self):
Expand Down Expand Up @@ -1036,7 +1036,7 @@ def auto_command(self, cmd, uuser, cchannel):
while ( a < len(self.kcs)):
kc=self.kcs[a]
a+=1
if kc[:len(cmd)]==string.lower(cmd):
if kc[:len(cmd)]==cmd.lower():
hit=kc
i+=1
if i >=2: #not unique
Expand Down Expand Up @@ -1261,7 +1261,7 @@ def command(self, user, channel, command, options):

elif command=="vote":
if not self.phase==NO_GAME:
if string.lower(options[:3].strip())=="end" or string.lower(options[:5].strip())=="abort":
if options[:3].strip().lower() == "end" or options[:5].strip().lower() == "abort":
self.vote_for_end(user)

elif command=="autoremove":
Expand Down Expand Up @@ -1459,10 +1459,10 @@ def command(self, user, channel, command, options):
SCOREHEAD=self.SCORETABLE+self.create_tab(pointlen-3+self.maxnicklen-12)+"_#UNDERLINE##DGREY#"+" Runde:"+str(self.roundofgame)
self.nipmsg("PRE_S"+SCOREHEAD, channel)
if len(self.allscore):
points=self.allscore.values()
points=list(self.allscore.values())
points.sort()
points.reverse()
players=self.allscore.keys()
players=list(self.allscore.keys())
for point in points:
for player in players:
if self.allscore[player]==point:
Expand Down Expand Up @@ -1730,8 +1730,8 @@ def msg(self, user, channel, msg):
if self.GAMECHANNEL==channel:

if self.phase==WAITING_FOR_PLAYERS and user!=self.bot.nickname: #add player with "ich" in first 42characters while startphase
if len(string.lower(msg).split("ich")[:42]) > 1: # parses *ich* just do that on WAITING_FOR_PLAYERS (startphase)
if len(string.lower(msg).split("nicht")[:24]) > 1: #yag
if len(msg.lower().split("ich")[:42]) > 1: # parses *ich* just do that on WAITING_FOR_PLAYERS (startphase)
if len(msg.lower().split("nicht")[:24]) > 1: #yag
if not user in self.players:
self.nipmsg("PRE_H Och schade "+user)
else:
Expand Down Expand Up @@ -1803,7 +1803,7 @@ def nip_hof(self,hofdataf,action):
thof[pair[0]]=int(pair[1])
hof.append("")
cnt+=1
pairs = sorted((key,value) for (value,key) in thof.iteritems())
pairs = sorted((key,value) for (value,key) in thof.items())
hcnt=len(pairs)-1
for value, key in pairs:
hof[hcnt]=key,value
Expand Down Expand Up @@ -1848,8 +1848,8 @@ def nip_hof(self,hofdataf,action):

def nip_hof_update(self, hofdataf):
if len(self.allscore):
points=self.allscore.values()
players=self.allscore.keys()
points=list(self.allscore.values())
players=list(self.allscore.keys())
for player in players:
point=self.allscore[player]
updateplayer=self.isinhof(str(player))
Expand Down Expand Up @@ -1887,14 +1887,14 @@ def isinhof(self, player, nocases=None):

def save_score(self,force=None):
#saving game scoring table for another external "HoF statistic" 4later use
if len(self.allscore.values()) > 0: #no need to save empty scoretable
if len(list(self.allscore.values())) > 0: #no need to save empty scoretable
self.bot.logger.debug("Saving score table")
ts=time.strftime('%Y%m%d_%H%M%S')
scorefile=self.niparchivdir+'NIPScore.'+ts
try:
sf=open(scorefile, "w")
sf.write("GameStartTime="+str(self.starttime)+"\nGameStopTime="+str(time.strftime('%Y/%m/%d %H:%M:%S'))+"\nNo. of Rounds="+str(self.roundofgame)+"\n")
for key, value in self.allscore.items():
for key, value in list(self.allscore.items()):
sf.write(str(key)+"="+str(value)+"\n")
sf.close()
except IOError:
Expand Down Expand Up @@ -1926,4 +1926,4 @@ def load_score(self):
sf.close()
except IOError:
self.bot.logger.error("IOError on "+scorefile)


2 changes: 1 addition & 1 deletion examples/tcpServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
USAGE = " <filename of unix socket> [stuff to send to tcpServer service]"

if len(sys.argv) < 2 or not os.path.exists(sys.argv[1]):
print sys.argv[0] + USAGE
print(sys.argv[0] + USAGE)
exit(1)

s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
Expand Down
2 changes: 1 addition & 1 deletion otfbot/lib/chatMod.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
""" contains a abstract class for a Bot-module """


from pluginSupport import Plugin
from .pluginSupport import Plugin


class chatMod(Plugin):
Expand Down
2 changes: 1 addition & 1 deletion otfbot/lib/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def filtercolors(input):
"""
Filters all irc colors out of a given string
"""
for i in xrange(1, 16):
for i in range(1, 16):
input = input.replace(chr(3) + str(i), "")
return input

Expand Down
6 changes: 3 additions & 3 deletions otfbot/lib/eliza.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ def setReflections(self, refl):

def setPatterns(self, pat):
self.patterns = {}
for key in pat.keys():
for key in list(pat.keys()):
self.patterns[re.compile(key, re.I)] = pat[key]

def reply(self, input):
for regex in self.patterns.keys():
for regex in list(self.patterns.keys()):
match = regex.match(input)
if match:
answer = random.choice(self.patterns[regex])
if "%s" in answer:
answer = answer % match.groups()
if answer[-2] in '.?!':
for refl in self.reflections.keys():
for refl in list(self.reflections.keys()):
answer = answer.replace(refl, self.reflections[refl])
answer = answer[:-1]
return answer
2 changes: 1 addition & 1 deletion otfbot/lib/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def loadProperties(propertiesFile, ambiguous=False, enc="ISO-8859-15"):
return {}
if os.path.exists(propertiesFile):
propFile = open(propertiesFile, "r")
content = unicode(propFile.read(), enc, errors='replace')
content = propFile.read()
propFile.close()
for line in content.split("\n"):
if len(line) > 1 and line[0] != "#":
Expand Down
6 changes: 3 additions & 3 deletions otfbot/lib/pluginSupport/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" module for providing a plugin-infrastructure to a twisted MultiService """
from pluginSupport import *
from plugin import *
from decorators import *
from .pluginSupport import *
from .plugin import *
from .decorators import *
Loading

0 comments on commit e145de0

Please sign in to comment.