-
Notifications
You must be signed in to change notification settings - Fork 0
/
RankModule.py
61 lines (54 loc) · 2.48 KB
/
RankModule.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -*- coding: utf-8 -*-
import CBE
class RankModule(CBE.CBEModule):
_cmdName = ""
def CheckConfig(self):
tempDict = {
"Rank_CMDName": "rank",
"Rank_CMDCooldown": 60,
"Rank_CMDIsGlobal": False,
"Rank_CMDUsage": "!rank [userid]",
"Rank_CMDDescription": "Shows the rank for the given user in the leaderboard (or the own, if none given)",
"Rank_CMDResponse": "$name is in place $rank with $currency $currencyname",
"Rank_CMDNoCurrencyYet": "$name has no $currencyname yet...",
"Rank_CMDFetchNumber": 100
}
for key in tempDict.keys():
if key not in self.cbe.Config.keys():
self.cbe.Config[key] = tempDict[key]
return
def RegisterHelp(self):
return
def RegisterCommands(self):
self._cmdName = self.cbe.Config["Rank_CMDName"]
self.cbe.AddCommand(self.cbe.Config["Rank_CMDName"], "Rank_CMDCooldown", "Rank_CMDIsGlobal", True, "Rank_CMDUsage", "Rank_CMDDescription", self.ProcessRank)
return
def RegisterUI(self):
self.cbe.AddUIFromFile("RankModule_UI.json")
return
def ReloadSettings(self, jsonData):
self.CheckConfig()
if self._cmdName != self.cbe.Config["Rank_CMDName"]:
self.cbe.RemoveCommand(self._cmdName)
self.RegisterCommands()
def ProcessRank(self, data):
usr = data.User
if data.GetParamCount() > 1:
usr = data.GetParam(1).lower()
usrname = self.cbe.GetDisplayName(usr)
currency = self.cbe.GetPoints(usr)
if currency > 0:
rank = ">" + str(self.cbe.Config["Rank_CMDFetchNumber"])
dic = self.cbe.GetTopCurrency(self.cbe.Config["Rank_CMDFetchNumber"])
listed = [(key, dic[key]) for key in dic.keys()]
listed.sort(cmp=lambda x,y: 1 if x[1] > y[1] else (0 if x[1] == y[1] else -1), reverse=True)
pos = 0
for elem in listed:
pos += 1
if elem[0] == usr:
rank = str(pos)
break
self.cbe.SendTwitchMessage(CBE.stemp(self.cbe.Config["Rank_CMDResponse"]).safe_substitute(name=usrname, rank=str(rank), currency=str(currency), currencyname=self.cbe.GetCurrencyName()))
else:
self.cbe.SendTwitchMessage(CBE.stemp(self.cbe.Config["Rank_CMDNoCurrencyYet"]).safe_substitute(name=usrname, currencyname=self.cbe.GetCurrencyName()))
return True