-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsettings.py
163 lines (150 loc) · 6.85 KB
/
settings.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
from enum import Enum
class Type(Enum):
transformation = 0
freeze = 1
encasement = 2
class Duration(Enum):
anyDuration = 0
short = 1
longDuration = 2
extended = 3
protracted = 4
class Settings:
def __init__ (self, name = "Helpless Subject", duration = Duration.longDuration, permanenceChance = 0.1, stripChance = 0.4, maxArticles = 2, expressionChance = 0.3, poseChance = 0.3, transformationAllowed = True, freezeAllowed = False, encasementAllowed = False, blacklist = [], custom = [], helpless = False):
vars(self).update((k,v) for k,v in vars().items() if k != 'self')
async def handle_set (client, message, name, channel, settings):
words = message.content.split(None, 2)
command = words[1].lower()
if (len(words) < 3 or words[1] == "help"):
await channel.send('Usage: !set <settingname> <value>\n' + \
'Valid settings: name, duration, permanenceChance, stripChance, maxArticles, expressionChance, poseChance, transformationAllowed, freezeAllowed, encasementAllowed, blacklist, custom\n' + \
'Choices for duration: a number 1-4 (short, long, extended, protracted) or 0 for random\n' + \
'Choices for "chance" values: a number 0-100\n' + \
'Choices for max articles: a number 0-6\n' + \
'Choices for "allowed" values: t or f\n' + \
'Choices for custom/blacklist: a comma-delimited string (or "none" to clear)')
return
if (command in ["name", "n"]):
await channel.send(f'{settings.name}, your new name is **{words[2]}**')
settings.name = words[2]
return
if (command in ["duration", "d"]):
duration = get_duration(words[2])
await channel.send(f'{settings.name}, your new duration setting is **{get_duration_description(duration)}**')
settings.duration = duration
return
if (command in ["permanencechance", "pec"]):
probability = probability_from_string(words[2])
await channel.send(f'{settings.name}, your new chance of a permanent effect is **{probability}%**')
settings.permanenceChance = probability / 100
return
if (command in ["stripchance", "sc"]):
probability = probability_from_string(words[2])
await channel.send(f'{settings.name}, your new chance of being stripped is **{probability}%**')
settings.stripChance = probability / 100
return
if (command in ["maxarticles", "ma"]):
articles = clamp_max_articles(words[2])
await channel.send(f'{settings.name}, your new maximum articles when being stripped is now **{articles}**')
settings.maxArticles = articles
return
if (command in ["expressionchance", "ec"]):
probability = probability_from_string(words[2])
await channel.send(f'{settings.name}, your new chance of being given an expression is **{probability}%**')
settings.expressionChance = probability / 100
return
if (command in ["posechance", "pc"]):
probability = probability_from_string(words[2])
await channel.send(f'{settings.name}, your new chance of being posed is **{probability}%**')
settings.poseChance = probability / 100
return
if (command in ["transformationallowed", "ta"]):
allowed = boolean_from_string(words[2])
await channel.send(f'{settings.name}, your new setting for transfomation allowed is **{allowed}**')
settings.transformationAllowed = allowed
return
if (command in ["freezeallowed", "fa"]):
allowed = boolean_from_string(words[2])
await channel.send(f'{settings.name}, your new setting for freeze allowed is **{allowed}**')
settings.freezeAllowed = allowed
return
if (command in ["encasementallowed", "ea"]):
allowed = boolean_from_string(words[2])
await channel.send(f'{settings.name}, your new setting for encasement allowed is **{allowed}**')
settings.encasementAllowed = allowed
return
if (command in ["custom", "c"]):
custom = word_list_from_string(words[2])
await channel.send(f'{settings.name}, your new custom material list is: **{custom}**')
settings.custom = custom
return
if (command in ["blacklist", "bl"]):
blacklist = word_list_from_string(words[2])
await channel.send(f'{settings.name}, your new material blacklist is: **{blacklist}**')
settings.blacklist = blacklist
return
def probability_from_string(input: str) -> int:
try:
parsedInput = int(input)
except:
return -1
if (parsedInput < 0):
parsedInput = 0
if (parsedInput > 100):
parsedInput = 100
return parsedInput
def clamp_max_articles(input: str) -> int:
try:
parsedInput = int(input)
except:
return 2
if (parsedInput < 0):
return 0
if (parsedInput > 6):
return 6
return parsedInput
def get_duration(input: str) -> Duration:
try:
parsedInput = int(input)
except:
return Duration.longDuration
if (parsedInput < 0 or parsedInput > 4):
return Duration.longDuration
return Duration(parsedInput)
def get_duration_description(duration: Duration) -> str:
return ["random", "short", "long", "extended", "protracted"][duration.value]
def boolean_from_string(input: str) -> bool:
if (input[0].lower() == 't'):
return True
return False
def word_list_from_string(input: str) -> list:
strings = input.split(",")
if (strings[0] == "none"):
return []
if (len(strings) > 30):
strings = strings[:30]
return [x.strip() for x in strings]
async def handle_view_settings (client, message, name, channel, settings):
await channel.send(f'**{name}**, your settings are:\n')
settings_string = f"""
**Name:** {settings.name}
**Helpless:** {settings.helpless}
**Duration:** {get_duration_description(settings.duration)}
**Permanence chance:** {settings.permanenceChance * 100}%
**Strip chance:** {settings.stripChance * 100}%
**Max articles:** {settings.maxArticles}
**Pose chance:** {settings.poseChance * 100}%
**Expression chance:** {settings.expressionChance * 100}%
**Transformation allowed:** {settings.transformationAllowed}
**Freeze allowed:** {settings.freezeAllowed}
**Encasement allowed:** {settings.encasementAllowed}
**Blacklist:** {settings.blacklist}
**Custom materials:** {settings.custom}
"""
await channel.send( settings_string)
async def handle_helpless (client, message, name, channel, settings):
settings.helpless = not settings.helpless
if (settings.helpless):
await channel.send(f'**{name}** is now helpless!')
else:
await channel.send(f'**{name}** is no longer helpless.')