forked from FailedSave/DiscordFateBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfate.py
183 lines (148 loc) · 7.08 KB
/
fate.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
from settings import Settings, Type
from setting_storage import find_settings_from_name
import discord
import asyncio
import random
import json
import stats_storage
delay = 0.9
async def handle_fate(client, message, name, channel, settings):
await client.send_message(channel, f'**{settings.name}**, your fate is...')
await asyncio.sleep(delay)
for string in get_fate_strings(settings):
await client.send_message(channel, string)
await asyncio.sleep(delay)
stats_storage.increment_fate()
async def handle_target_fate(client, message, name, channel, settings):
words = message.content.split(None, 1)
if len(words) < 2:
await client.send_message(channel, f"This command needs a target.")
return
target_name = words[1]
target_settings = find_settings_from_name(target_name)
if target_settings is None:
await client.send_message(channel, f"**{target_name}** not found. (Have they ever interacted with me?)")
return
elif not target_settings.helpless:
await client.send_message(channel, f"**{target_name}** is not helpless!")
return
await client.send_message(channel, f'**{target_name}**, **{message.author.name}** has decided that your fate is...')
await asyncio.sleep(delay)
for string in get_fate_strings(settings):
await client.send_message(channel, string)
await asyncio.sleep(delay)
stats_storage.increment_fate()
async def handle_whisper_fate(client, message, name, channel, settings):
words = message.content.split(None, 1)
if len(words) < 2:
await client.send_message(channel, f"This command needs a target.")
return
target_name = words[1]
target_settings = find_settings_from_name(target_name)
if target_settings is None:
await client.send_message(channel, f"**{target_name}** not found. (Have they ever interacted with me?)")
return
elif not target_settings.helpless:
await client.send_message(channel, f"**{target_name}** is not helpless!")
return
target_fate = get_fate_strings(settings)
await client.send_message(target_settings.user, f'**{target_name}**, **{message.author.name}** has decided that your fate is...')
target_fate_string = f"**{target_name}'s** fate is...\n"
await asyncio.sleep(delay)
for string in target_fate:
await client.send_message(target_settings.user, string)
await asyncio.sleep(delay)
target_fate_string = target_fate_string + string + "\n"
await client.send_message(message.author, target_fate_string)
stats_storage.increment_fate()
def get_fate_strings(settings: Settings) -> list:
strings = []
if (check_probability(settings.stripChance)):
strings.append(get_message_for_strip(settings))
type_and_material = get_type_and_material(settings)
strings.append(get_message_for_type_and_material(type_and_material))
if (check_probability(settings.expressionChance)):
strings.append(get_message_for_expression(type_and_material["effectType"]))
if (check_probability(settings.poseChance)):
strings.append(get_message_for_pose(settings))
strings.append(get_duration_message(settings))
return strings
with open('data.json') as json_data:
d = json.load(json_data)
poseList = d["poseList"]
transformationMaterialsList = d["transformationMaterialsList"]
freezeMaterialsList = d["freezeMaterialsList"]
encasementMaterialsList = d["encasementMaterialsList"]
transformationExpressionList = d["transformationExpressionList"]
freezeExpressionList = d["freezeExpressionList"]
encasementExpressionList = d["encasementExpressionList"]
durationsListOfLists = [d["shortDurationList"], d["longDurationList"], d["extendedDurationList"], d["protractedDurationList"]]
def get_type_and_material(settings: Settings):
allowedTypes = []
if (settings.transformationAllowed):
allowedTypes.append(Type.transformation)
if (settings.freezeAllowed):
allowedTypes.append(Type.freeze)
if (settings.encasementAllowed):
allowedTypes.append(Type.encasement)
if (len(allowedTypes)) == 0:
allowedTypes.append(Type.transformation)
allowed_materials = []
effectType = random.choice(allowedTypes)
if (effectType == Type.transformation):
allowed_materials.extend(transformationMaterialsList)
if (effectType == Type.freeze):
allowed_materials.extend(freezeMaterialsList)
if (effectType == Type.encasement):
allowed_materials.extend(encasementMaterialsList)
allowed_materials = [material for material in allowed_materials if does_not_contain_any(material, settings.blacklist)]
for item in settings.custom:
allowed_materials.append(item)
if len(allowed_materials) == 0:
allowed_materials.append("an inoffensive thing")
return {"effectType": effectType, "material": random.choice(allowed_materials)}
def does_not_contain_any(input: str, blacklist: list):
for item in blacklist:
if (input.find(item) >= 0):
return False
return True
def check_probability(chance) -> bool:
return random.random() < chance
def get_message_for_strip(settings) -> str:
articles = random.randint(0, settings.maxArticles)
if (articles == 0):
return "You will be stripped **completely naked**..."
elif (articles == 1):
return "You will be stripped **down to 1 article of clothing**..."
else:
return f"You will be stripped **down to {articles} articles of clothing**..."
def get_message_for_pose(settings) -> str:
return f"...you are posed {random.choice(poseList)}..."
def get_message_for_expression(effectType) -> str:
expressionChoices = ["invalid effect type"]
if (effectType == Type.transformation):
expressionChoices = transformationExpressionList
elif (effectType == Type.freeze):
expressionChoices = freezeExpressionList
elif (effectType == Type.encasement):
expressionChoices = encasementExpressionList
return f"...{random.choice(expressionChoices)}..."
def get_message_for_type_and_material(type_and_material) -> str:
effectType = type_and_material["effectType"]
material = type_and_material["material"]
if (effectType == Type.transformation):
return f'You will be turned into **{material}**...'
elif (effectType == Type.freeze):
return f'You will be **{material}**...'
elif (effectType == Type.encasement):
return f'You will be encased in **{material}**...'
else:
return f'Error: invalid effect type'
def get_duration_message(settings) -> str:
if (check_probability(settings.permanenceChance)):
return "...you will stay that way **permanently!**"
duration = settings.duration.value
if (duration == 0):
duration = random.randint(1, 4)
time = random.choice(durationsListOfLists[duration - 1])
return f"...you will stay that way for the next **{time}**."