-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSugus_VS_Chocobons_StreamlabsSystem.py
97 lines (82 loc) · 2.83 KB
/
Sugus_VS_Chocobons_StreamlabsSystem.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/python
# -*- coding: utf-8 -*-
#---------------------------------------
# Import Libraries
#---------------------------------------
import sys
import os
import json
import codecs
import clr
clr.AddReference("IronPython.SQLite.dll")
clr.AddReference("IronPython.Modules.dll")
#---------------------------------------
# [Required] Script Information
#---------------------------------------
ScriptName = "Sugus VS Chocobons"
Website = "http://bgon.es"
Description = "Contador de usuarios que prefieren Sugus o Chocobons"
Creator = "BGON"
Version = "1.0"
#---------------------------------------
# Settings Class
#---------------------------------------
SettingsFile = os.path.join(os.path.dirname(__file__), "settings.json")
class Settings(object):
def __init__(self, settingsfile=None):
try:
with codecs.open(settingsfile, encoding="utf-8-sig", mode="r") as f:
self.__dict__ = json.load(f, encoding="utf-8")
except:
self.cooldown_user = 10
self.api_url = ""
self.api_user = ""
self.api_key = ""
return
def Reload(self, jsondata):
self.__dict__ = json.loads(jsondata, encoding="utf-8")
return
#---------------------------------------
# [Required] Intialize Data
#---------------------------------------
def Init():
global Settings
Settings = Settings(SettingsFile)
return
#---------------------------------------
# [Required] Process messages
#---------------------------------------
def Execute(data):
if data.IsChatMessage() and data.IsFromTwitch() and not Parent.IsOnUserCooldown(ScriptName, "", data.User):
preference = data.GetParam(0).lower()
if '!sugus':
preference = 'sugus'
elif preference == '!chocobons':
preference = 'chocobons'
else:
return
raw_data = ParseRawData( data.RawData )
if RequestPreference(raw_data['user-id'], data.UserName, preference):
Parent.AddUserCooldown(ScriptName, "", data.User, Settings.cooldown_user)
return
#---------------------------------------
# [Required] Tick Function
#---------------------------------------
def Tick():
return
#---------------------------------------
# Save the key in server
#---------------------------------------
def RequestPreference(twitch_id, twitch_name, preference):
target_url = "{}?user={}&key={}&twitch_id={}&twitch_name={}&preference={}".format(Settings.api_url, Settings.api_user, Settings.api_key, twitch_id, twitch_name, preference)
response = json.loads(Parent.GetRequest(target_url,{}))
return response["status"] == 200
#---------------------------------------
# Parse raw data to dictionary
#---------------------------------------
def ParseRawData( rawData ):
parsed = {}
for singleData in rawData.split(";"):
singleDataSplitted = singleData.split("=")
parsed[singleDataSplitted[0]] = singleDataSplitted[1]
return parsed