-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathomoikane.py
751 lines (711 loc) · 23.4 KB
/
omoikane.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
import interactions
from interactions.ext.paginator import Page, Paginator
import random
import cypher
import fun
import secrets
token = secrets.token()
bot = interactions.Client(token=token)
# Roll a d20 with Cypher formatting
@bot.command(
name="roll",
description="Roll for it!",
options = [
interactions.Option(
name="difficulty",
description="Difficulty Rating",
type=interactions.OptionType.INTEGER,
required=False,
),
interactions.Option(
name="training",
description="How much training do you have?",
type=interactions.OptionType.INTEGER,
required=False,
),
interactions.Option(
name="assets",
description="How many assets do you have?",
type=interactions.OptionType.INTEGER,
required=False,
),
interactions.Option(
name="effort",
description="How much effort are you putting in?",
type=interactions.OptionType.INTEGER,
required=False,
),
],
)
async def roll(ctx: interactions.CommandContext, difficulty: int = 0, training: int = 0, assets: int = 0, effort: int = 0):
output = cypher.print_roll(difficulty, training, assets, effort)
await ctx.send(output)
# Roll xdx
@bot.command(
name="dice",
description="Roll xdx",
options = [
interactions.Option(
name="number",
description="Number of dice",
type=interactions.OptionType.INTEGER,
required=True,
),
interactions.Option(
name="sides",
description="Number of sides",
type=interactions.OptionType.INTEGER,
required=True,
),
],
)
async def dice(ctx: interactions.CommandContext, number: int, sides: int):
output = cypher.roll(number, sides)
await ctx.send(output)
# Roll a random cypher from dataframe
@bot.command(
name="cypher",
description="Rolls a random tropey cypher",
)
async def roll_cypher(ctx: interactions.CommandContext):
output = cypher.print_cypher()
await ctx.send(output)
# Look up a specific Cypher ability
# This is currently case-sensitive (and spelling sensitive)
@bot.command(
name="ability",
description="Ability lookup",
options = [
interactions.Option(
name="text",
description="What ability?",
type=interactions.OptionType.STRING,
required=True,
),
],
)
async def ability(ctx: interactions.CommandContext, text: str):
output = cypher.print_ability(text)
await ctx.send(output)
# Look at a specific character sheet
# Sometimes we don't want the full sheet,
# so this first one is just for stat pools.
@bot.command(
name="status",
description="View character status",
options = [
interactions.Option(
name="character",
description="What character?",
type=interactions.OptionType.STRING,
required=True,
),
],
)
async def status(ctx: interactions.CommandContext, character: str):
output = cypher.profile(character)
await ctx.send(output)
# Sometimes, we DO want the full character sheet!
@bot.command(
name="sheet",
description="View full character sheet",
options = [
interactions.Option(
name="character",
description="What character?",
type=interactions.OptionType.STRING,
required=True,
),
],
)
async def sheet(ctx: interactions.CommandContext, character: str):
await Paginator(
client=bot,
ctx=ctx,
pages=[
Page(cypher.profile(character), title="Stats"),
Page(cypher.skills(character), title="Skills"),
Page(cypher.abilities(character), title="Abilities"),
Page(cypher.equipment(character), title="Equipment"),
Page(cypher.notes(character), title="Notes"),
],
author_only=True,
).run()
# Spend points
@bot.command(
name="spend",
description="Spend from pools",
options = [
interactions.Option(
name="character",
description="What character?",
type=interactions.OptionType.STRING,
required=True,
),
interactions.Option(
name="might",
description="How much might?",
type=interactions.OptionType.INTEGER,
required=False,
),
interactions.Option(
name="speed",
description="How much speed?",
type=interactions.OptionType.INTEGER,
required=False,
),
interactions.Option(
name="intellect",
description="How much intellect?",
type=interactions.OptionType.INTEGER,
required=False,
),
interactions.Option(
name="xp",
description="How much XP?",
type=interactions.OptionType.INTEGER,
required=False,
),
],
)
async def spend(ctx: interactions.CommandContext, character: str, might: int=0, speed: int=0, intellect: int=0, xp: int=0):
output = cypher.spend(name=character, might=might, speed=speed, intel=intellect, xp=xp)
await ctx.send(output)
# Recover points
@bot.command(
name="recover",
description="Recover lost points",
options = [
interactions.Option(
name="character",
description="What character?",
type=interactions.OptionType.STRING,
required=True,
),
interactions.Option(
name="might",
description="How much might?",
type=interactions.OptionType.INTEGER,
required=False,
),
interactions.Option(
name="speed",
description="How much speed?",
type=interactions.OptionType.INTEGER,
required=False,
),
interactions.Option(
name="intellect",
description="How much intellect?",
type=interactions.OptionType.INTEGER,
required=False,
),
],
)
async def recover(ctx: interactions.CommandContext, character: str, might: int=0, speed: int=0, intellect: int=0):
output = cypher.recover(name=character, might=might, speed=speed, intel=intellect)
await ctx.send(output)
# Award XP
@bot.command(
name="xp",
description="Award XP",
options = [
interactions.Option(
name="character",
description="What character?",
type=interactions.OptionType.STRING,
required=True,
),
interactions.Option(
name="amount",
description="How much XP?",
type=interactions.OptionType.INTEGER,
required=True,
),
],
)
async def xp(ctx: interactions.CommandContext, character: str, amount: int):
output = cypher.add_xp(name=character, amount=amount)
await ctx.send(output)
# Advance
@bot.command(
name="advance",
description="Spend XP on advancement",
options = [
interactions.Option(
name="character",
description="What character?",
type=interactions.OptionType.STRING,
required=True,
),
interactions.Option(
name="pools",
description="If advancing pools, use format XXXX (example: mmsi)",
type=interactions.OptionType.STRING,
required=False,
),
interactions.Option(
name="effort",
description="If advancing effort, type whatever here, just don't leave it blank.",
type=interactions.OptionType.STRING,
required=False,
),
interactions.Option(
name="edge",
description="If advancing edge, type m, s, or i to choose.",
type=interactions.OptionType.STRING,
required=False,
),
interactions.Option(
name="skill",
description="If advancing skill, this isn't being tracked yet. Type whatever, just don't leave it blank.",
type=interactions.OptionType.STRING,
required=False,
),
interactions.Option(
name="other",
description="If taking other advancement option, this isn't being tracked yet. Type anything (not blank!).",
type=interactions.OptionType.STRING,
required=False,
),
],
)
async def advance(ctx: interactions.CommandContext, character: str, pools: str=None, effort: str=None, edge: str=None, skill: str=None, other: str=None):
output = cypher.advance(name=character, pools=pools, effort=effort, edge=edge, skill=skill, other=other)
await ctx.send(output)
# Rest
@bot.command(
name="rest",
description="Rest up",
options = [
interactions.Option(
name="character",
description="What character?",
type=interactions.OptionType.STRING,
required=True,
),
],
)
async def rest(ctx: interactions.CommandContext, character: str):
output = cypher.rest(name=character)
await ctx.send(output)
# Set up a new character sheet
@bot.command(
name="setup",
description="Create a new character",
options = [
interactions.Option(
name="lookup_name",
description="Short name (used for lookups)",
type=interactions.OptionType.STRING,
required=True,
),
interactions.Option(
name="full_name",
description="Full name",
type=interactions.OptionType.STRING,
required=True,
),
interactions.Option(
name="descriptor",
description="Descriptor",
type=interactions.OptionType.STRING,
required=True,
),
interactions.Option(
name="ctype",
description="Type",
type=interactions.OptionType.STRING,
required=True,
),
interactions.Option(
name="focus",
description="Focus",
type=interactions.OptionType.STRING,
required=True,
),
interactions.Option(
name="flavor",
description="Flavor",
type=interactions.OptionType.STRING,
required=False,
),
interactions.Option(
name="might",
description="Might Pool",
type=interactions.OptionType.INTEGER,
required=False,
),
interactions.Option(
name="speed",
description="Speed Pool",
type=interactions.OptionType.INTEGER,
required=False,
),
interactions.Option(
name="intellect",
description="Intellect Pool",
type=interactions.OptionType.INTEGER,
required=False,
),
interactions.Option(
name="might_edge",
description="Might Edge",
type=interactions.OptionType.INTEGER,
required=False,
),
interactions.Option(
name="speed_edge",
description="Speed Edge",
type=interactions.OptionType.INTEGER,
required=False,
),
interactions.Option(
name="intellect_edge",
description="Intellect Edge",
type=interactions.OptionType.INTEGER,
required=False,
),
],
)
async def setup(ctx: interactions.CommandContext, lookup_name: str, full_name: str, descriptor: str, ctype: str, focus: str, flavor:str = "", might: int=8, speed: int=8, intellect: int=8, might_edge:int=0, speed_edge:int=0, intellect_edge:int=0):
output = cypher.setup_character(name=lookup_name, full_name=full_name, desc=descriptor, ctype=ctype, focus=focus, flavor = flavor, m = might, s = speed, i = intellect, m_e = might_edge, s_e = speed_edge, i_e = intellect_edge)
await ctx.send(output)
# Edit character sheet
# Edit Skills
@bot.command(
name="edit_skills",
description="Edit your skills page on your character sheet",
options = [
interactions.Option(
name="character",
description="What character?",
type=interactions.OptionType.STRING,
required=True,
),
],
)
async def edit_skills(ctx: interactions.CommandContext, character: str):
current_trained = cypher.trained_lookup(character)
current_spec = cypher.spec_lookup(character)
current_inability = cypher.inability_lookup(character)
name_component = interactions.TextInput(
style = interactions.TextStyleType.SHORT,
label = "Name: (Don't change this!)",
custom_id = 'character',
value = character,
)
trained_component = interactions.TextInput(
style = interactions.TextStyleType.PARAGRAPH,
label = "Trained:",
custom_id = 'trained_update',
value = current_trained,
)
spec_component = interactions.TextInput(
style = interactions.TextStyleType.PARAGRAPH,
label = "Specialized:",
custom_id = 'spec_update',
value = current_spec,
)
inability_component = interactions.TextInput(
style = interactions.TextStyleType.PARAGRAPH,
label = "Inability:",
custom_id = 'inability_update',
value = current_inability,
)
modal = interactions.Modal(
title="Edit Skills",
custom_id = "edit_skills",
components = [name_component, trained_component, spec_component, inability_component],
)
await ctx.popup(modal)
@bot.modal("edit_skills")
async def modal_response_skills(ctx, character: str, trained_update: str, spec_update: str, inability_update: str):
output = cypher.skills_update(character, trained_update, spec_update, inability_update)
await ctx.send(output)
# Edit Abilities
@bot.command(
name="edit_abilities",
description="Edit your abilities page on your character sheet",
options = [
interactions.Option(
name="character",
description="What character?",
type=interactions.OptionType.STRING,
required=True,
),
],
)
async def edit_abilities(ctx: interactions.CommandContext, character: str):
current_abilities = cypher.ability_lookup(character)
name_component = interactions.TextInput(
style = interactions.TextStyleType.SHORT,
label = "Name: (Don't change this!)",
custom_id = 'character',
value = character,
)
abilities_component = interactions.TextInput(
style = interactions.TextStyleType.PARAGRAPH,
label = "Abilities:",
custom_id = 'abilities_update',
value = current_abilities,
)
modal = interactions.Modal(
title="Edit Abilities",
custom_id = "edit_abilities",
components = [name_component, abilities_component],
)
await ctx.popup(modal)
@bot.modal("edit_abilities")
async def modal_response_abilities(ctx, character: str, abilities_update: str):
output = cypher.ability_update(character, abilities_update)
await ctx.send(output)
# Edit inventory
@bot.command(
name="edit_inventory",
description="Edit your inventory page on your character sheet",
options = [
interactions.Option(
name="character",
description="What character?",
type=interactions.OptionType.STRING,
required=True,
),
],
)
async def edit_inventory(ctx: interactions.CommandContext, character: str):
current_cypher = cypher.cypher_lookup(character)
current_equipment = cypher.equip_lookup(character)
name_component = interactions.TextInput(
style = interactions.TextStyleType.SHORT,
label = "Name: (Don't change this!)",
custom_id = 'character',
value = character,
)
cypher_component = interactions.TextInput(
style = interactions.TextStyleType.PARAGRAPH,
label = "Cyphers:",
custom_id = 'cypher_update',
value = current_cypher,
)
equip_component = interactions.TextInput(
style = interactions.TextStyleType.PARAGRAPH,
label = "Equipment:",
custom_id = 'equip_update',
value = current_equipment,
)
modal = interactions.Modal(
title="Edit Inventory",
custom_id = "edit_inventory",
components = [name_component, cypher_component, equip_component],
)
await ctx.popup(modal)
@bot.modal("edit_inventory")
async def modal_response_inventory(ctx, character: str, cypher_update: str, equip_update: str):
output = cypher.inventory_update(character, cypher_update, equip_update)
await ctx.send(output)
# Edit notes page
@bot.command(
name="edit_notes",
description="Edit your notes page on your character sheet",
options = [
interactions.Option(
name="character",
description="What character?",
type=interactions.OptionType.STRING,
required=True,
),
],
)
async def edit_notes(ctx: interactions.CommandContext, character: str):
current_notes = cypher.notes_lookup(character)
name_component = interactions.TextInput(
style = interactions.TextStyleType.SHORT,
label = "Name: (Don't change this!)",
custom_id = 'character',
value = character,
)
notes_component = interactions.TextInput(
style = interactions.TextStyleType.PARAGRAPH,
label = "Notes:",
custom_id = 'notes_update',
value = current_notes,
)
modal = interactions.Modal(
title="Edit Notes",
custom_id = "edit_notes",
components = [name_component, notes_component],
)
await ctx.popup(modal)
@bot.modal("edit_notes")
async def modal_response_notes(ctx, character: str, notes_update: str):
output = cypher.ability_update(character, notes_update)
await ctx.send(output)
# Message Dripper, FIFO, from txt file
# The "dripper" is started with a slash command,
# then spawns a button that can be pressed to continue
button = interactions.Button(
style=interactions.ButtonStyle.PRIMARY,
label = "More!",
custom_id="drip_button"
)
@bot.command(
name="drip",
description="Drip start!",
)
async def drip(ctx: interactions.CommandContext):
dripfile = 'Assets/dripper.txt'
with open(dripfile, 'r+', encoding='utf8') as f:
firstline = f.readline()
data = f.read()
f.seek(0)
f.write(data)
f.truncate()
await ctx.send(firstline, components=button)
@bot.component("drip_button")
async def drip_button_response(ctx):
await ctx.edit(components=None)
dripfile = 'Assets/dripper.txt'
with open(dripfile, 'r+', encoding='utf8') as f:
firstline = f.readline()
data = f.read()
f.seek(0)
f.write(data)
f.truncate()
await ctx.send(firstline, components=button)
# NLTK n-gram fake plot creator
@bot.command(
name="plot",
description="Generate random plotting things!",
options = [
interactions.Option(
name="feeder",
description="1 or 2 words to get it started (optional)",
type=interactions.OptionType.STRING,
required=False,
),
interactions.Option(
name="exclusions",
description="What words would you like to exclude? (optional)",
type=interactions.OptionType.STRING,
required=False,
),
],
)
async def plot(ctx: interactions.CommandContext, feeder: str = None, exclusions: str = None):
output = fun.two_seed_generator(feeder, exclusions)
await ctx.send(output)
# Mad libs style string filler
@bot.command(
name="filler",
description="Fills instances of verb, noun, person, place, adj, adv, color, and emotion, mad lib style.",
options = [
interactions.Option(
name="text",
description="Full text to fill",
type=interactions.OptionType.STRING,
required=True,
),
],
)
async def filler(ctx: interactions.CommandContext, text: str):
output = fun.filler(text)
await ctx.send(output)
# Make the bot make the choices
bot.command(
name="choose",
description="Forces the bot to make the hard decisions... or any decision at all. Use | to separate choices",
options = [
interactions.Option(
name="text",
description="All choices, separated by |",
type=interactions.OptionType.STRING,
required=True,
),
],
)
async def choose(ctx: interactions.CommandContext, text: str):
options = text.split("|")
choice = random.choice(options)
await ctx.send(choice)
# Initiative Tracker
# Start accepting initiative rolls
@bot.command(
name="initiative_tracker",
description="Initializes the initiative tracker",
)
async def initative_tracker(ctx: interactions.CommandContext):
output = cypher.track_initiative()
await ctx.send(output)
# Stop accepting initiative rolls
@bot.command(
name="initiative_end",
description="Stops tracking initiative",
)
async def initative_end(ctx: interactions.CommandContext):
output = cypher.untrack_initiative()
await ctx.send(output)
# Roll initiative for a character
@bot.command(
name="initiative",
description="Roll for initiative!",
options = [
interactions.Option(
name="character",
description="What character?",
type=interactions.OptionType.STRING,
required=True,
),
],
)
async def initiative(ctx: interactions.CommandContext, character: str):
initiative_value = cypher.roll_initiative(character)
output = cypher.add_initiative(character, initiative_value)
await ctx.send(output)
# Remove initiative for a character
@bot.command(
name="initiative_rm",
description="Remove a character from the initiative tracker",
options = [
interactions.Option(
name="character",
description="What character?",
type=interactions.OptionType.STRING,
required=True,
),
],
)
async def initiative_rm(ctx: interactions.CommandContext, character: str):
output = cypher.rm_initiative(character)
await ctx.send(output)
# Begin combat!
tracker_button = interactions.Button(
style=interactions.ButtonStyle.PRIMARY,
label = "End Turn",
custom_id="turn_button"
)
@bot.command(
name="initiative_start",
description="Print the initiative tracker and begin!",
)
async def initiative_start(ctx: interactions.CommandContext):
output = cypher.print_initiative()
sorted_rows, sorted_names = cypher.sort_initiative()
first_up = sorted_names[0]
with open('Cypher/current_player.txt', 'r+', encoding='utf8') as f:
f.write(first_up)
first_up_msg = "First up is {}! Once your turn is complete, remember to hit the End Turn button to advance the tracker.".format(first_up)
await ctx.send(output)
await ctx.send(first_up_msg, components=tracker_button)
@bot.component("turn_button")
async def turn_button_response(ctx):
await ctx.edit(components=None)
with open('Cypher/current_player.txt', 'r+', encoding='utf8') as f:
current_player = f.readline()
next_player = cypher.next_player(current_player)
f.seek(0)
f.write(next_player)
f.truncate()
output = "{}, it's your turn! Please hit End Turn once you've completed your turn.".format(next_player)
await ctx.send(output, components=tracker_button)
bot.start()