|
1 | 1 | # PyBot is a Twitch IRC chatbot used particularly for spamming your chat, but as well as a general chatbot for doing whatever.
|
2 |
| -# Copyright (C) 2016 Sheep44 |
| 2 | +# Copyright (C) 2016-2018 Sheep44 |
3 | 3 | #
|
4 | 4 | # This file is part of PyBot.
|
5 | 5 | #
|
|
13 | 13 | # GNU General Public License for more details.
|
14 | 14 |
|
15 | 15 |
|
| 16 | +# NOTE: Move from username to user ID |
16 | 17 |
|
17 |
| -# This is an unfinished file and is not for use until it is patched up. |
18 | 18 | import threading
|
19 |
| -from Settings import CHANNEL |
| 19 | +from requests import request as req |
| 20 | +from Settings import CHANNEL, PASS |
20 | 21 | from time import sleep as t
|
21 |
| -import urllib.request |
22 | 22 | from os.path import isfile
|
23 |
| -printLock = threading.Lock() |
| 23 | + |
| 24 | + |
24 | 25 | _pointsList = {}
|
| 26 | +chatInfo = {} |
| 27 | +_pointsFileName = "points/" + CHANNEL + ".json" |
25 | 28 | def points():
|
26 |
| - justStarted = True |
27 |
| - global _pointsList |
28 |
| - _pointsFileName = "points_" + CHANNEL + ".json" |
29 |
| - if isfile(_pointsFileName): |
30 |
| - _pointsFileRead = open(_pointsFileName, 'r') |
31 |
| - _pointsList = eval(_pointsFileRead.read()) |
32 |
| - while True: |
33 |
| - chatInfo = eval(urllib.request.urlopen("https://tmi.twitch.tv/group/user/" + CHANNEL + "/chatters").read()) |
34 |
| - chatters = chatInfo["chatters"] |
35 |
| - mods = chatters["moderators"] |
36 |
| - staff = chatters["staff"] |
37 |
| - admins = chatters["admins"] |
38 |
| - gMods = chatters["global_mods"] |
39 |
| - viewers = chatters["viewers"] |
40 |
| - if justStarted: |
41 |
| - justStarted = False |
42 |
| - else: |
43 |
| - for i in viewers: |
44 |
| - if i in _pointsList.keys(): |
45 |
| - _pointsList[i] += 5 |
46 |
| - else: |
47 |
| - _pointsList[i] = 0 |
48 |
| - for i in mods: |
49 |
| - if i in _pointsList.keys(): |
50 |
| - _pointsList[i] += 5 |
51 |
| - else: |
52 |
| - _pointsList[i] = 0 |
53 |
| - for i in staff: |
54 |
| - if i in _pointsList.keys(): |
55 |
| - _pointsList[i] += 5 |
56 |
| - else: |
57 |
| - _pointsList[i] = 0 |
58 |
| - for i in admins: |
59 |
| - if i in _pointsList.keys(): |
60 |
| - _pointsList[i] += 5 |
61 |
| - else: |
62 |
| - _pointsList[i] = 0 |
63 |
| - for i in gMods: |
64 |
| - if i in _pointsList.keys(): |
65 |
| - _pointsList[i] += 5 |
66 |
| - else: |
67 |
| - _pointsList[i] = 0 |
68 |
| - |
69 |
| - _pointsFileWrite = open(_pointsFileName, 'w') |
70 |
| - _pointsFileWrite.write(str(_pointsList)) |
71 |
| - t(60) |
| 29 | + global _pointsList |
| 30 | + global chatInfo |
| 31 | + justStarted = True |
| 32 | + if isfile(_pointsFileName): |
| 33 | + try: |
| 34 | + _pointsList = eval(open(_pointsFileName, 'r')) |
| 35 | + except: |
| 36 | + __ = open(_pointsFileName, 'w') |
| 37 | + __.close() |
| 38 | + del __ |
| 39 | + while True: |
| 40 | + chatInfo = eval( |
| 41 | + req( |
| 42 | + method="GET", |
| 43 | + url="https://tmi.twitch.tv/group/user/%s/chatters" % CHANNEL |
| 44 | + ).text |
| 45 | + ) |
| 46 | + chatters = chatInfo["chatters"] |
| 47 | + if justStarted: |
| 48 | + justStarted = False |
| 49 | + else: |
| 50 | + for x in chatters: |
| 51 | + for i in chatInfo["chatters"][x]: |
| 52 | + if i in _pointsList.keys() and "bot" not in i: |
| 53 | + _pointsList[i] += 5 |
| 54 | + elif "bot" not in i: |
| 55 | + _pointsList[i] = 5 |
| 56 | + with open(_pointsFileName, 'w') as f: |
| 57 | + f.write(str(_pointsList)) |
| 58 | + f.close() |
| 59 | + t(60) |
72 | 60 |
|
73 | 61 |
|
74 | 62 | thread = threading.Thread(target=points)
|
|
0 commit comments