Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Before you continue, I should note that I was *not* the one to make these. These codes were graciously provided to me by another bot coder (MyNameIsChriz) so that I could update my own bot's connection to Chatango chatrooms.
- #The self.server assignment in def: __init__ of class chatroom should be updated to use the new getServer helper method.
- self.server = getServer(self.name)
- #I just put these toward the top of "Helper Methods," the bottom-most category of code in chatango.py. It is a helper method, after all.
- nspecials = {'mitvcanal': 56}
- tsweights = [['5', 61], ['6', 61], ['7', 61], ['8', 61], ['16', 61], ['17', 61], ['9', 90], ['11', 90], ['13', 90], ['14', 90], ['15', 90], ['23', 110], ['24', 110], ['25', 110], ['28', 104], ['29', 104], ['30', 104], ['31', 104], ['32', 104], ['33', 104], ['35', 101], ['36', 101], ['37', 101], ['38', 101], ['39', 101], ['40', 101], ['41', 101], ['42', 101], ['43', 101], ['44', 101], ['45', 101], ['46', 101], ['47', 101], ['48', 101], ['49', 101], ['50', 101], ['57', 110], ['58', 110], ['59', 110], ['60', 110], ['61', 110], ['62', 110], ['63', 110], ['64', 110], ['65', 110], ['66', 110]]
- def getServer(group):
- '''
- Get the server host for a certain room.
- @type group: str
- @param group: room name
- @rtype: str
- @return: the server's hostname
- '''
- try:
- sn = nspecials[group]
- except KeyError:
- group = group.replace("_", "q")
- group = group.replace("-", "q")
- fnv = float(int(group[0:min(5, len(group))], 36))
- lnv = group[6: (6 + min(3, len(group) - 5))]
- if(lnv):
- lnv = float(int(lnv, 36))
- if(lnv <= 1000):
- lnv = 1000
- else:
- lnv = 1000
- num = (fnv % lnv) / lnv
- maxnum = sum(map(lambda x: x[1], tsweights))
- cumfreq = 0
- sn = 0
- for wgt in tsweights:
- cumfreq += float(wgt[1]) / maxnum
- if(num <= cumfreq):
- sn = int(wgt[0])
- break
- return "s" + str(sn) + ".chatango.com"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement