-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
97 lines (81 loc) · 3.41 KB
/
Copy pathbot.py
File metadata and controls
97 lines (81 loc) · 3.41 KB
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
import discord
from discord.ext import commands
from discord import Option, ApplicationContext, SlashCommandOptionType
import sys
from api.bonkApi import *
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(intents=intents)
@bot.slash_command(name="jail", guild_only = True, description="Send a user to jail for an offense")
async def jailSlashCommand(
ctx: ApplicationContext,
user: Option(SlashCommandOptionType.user, "Who should go to jail"),
offense: Option(str, "What they should go to jail for")
):
resultOrError = jailCall(ctx.guild_id, user.id, offense)
if resultOrError.isFailure():
await ctx.respond("Unknown error")
rapsheetString = await getRapsheetString(ctx, user)
await ctx.respond(f"Sent {user.name} to jail for {offense}" + "\n" + rapsheetString)
@bot.slash_command(name="addoffense", guild_only = True, description="Add a new jailable offense")
async def addOffenseSlashCommand(
ctx: ApplicationContext,
offense: Option(str, "Name of the offense you want to add")
):
resultOrError = addOffenseCall(ctx.guild_id, offense)
if resultOrError.isFailure():
await ctx.respond("Unknown error")
offenseListString = await getOffenseListString(ctx)
await ctx.respond(f"Added {offense} as a possible offense" + "\n" + offenseListString)
@bot.slash_command(name="rapsheet", guild_only = True, description="Get a list of offenses for the user")
async def rapSheetSlashCommand(
ctx: ApplicationContext,
user: Option(SlashCommandOptionType.user, "Whose rapsheet to find")
):
await ctx.respond(await getRapsheetString(ctx, user))
@bot.slash_command(name="listoffenses", guild_only = True, description="Get the list of valid offenses for the server")
async def listOffensesSlashCommand(
ctx: ApplicationContext
):
await ctx.respond(await getOffenseListString(ctx))
async def getOffenseListString(ctx):
resultOrError = getOffensesCall(ctx.guild_id)
if resultOrError.isFailure():
await ctx.respond("Unknown error")
offenseList = resultOrError.result["offenses"]
returnString = "Possible Offenses: "
returnString += ", ".join(offenseList)
return returnString
async def getRapsheetString(ctx, user):
resultOrError = rapsheetCall(ctx.guild_id, user.id)
if resultOrError.isFailure():
await ctx.respond("Unknown error")
rapsheet = resultOrError.result["rapSheet"]
returnString = f"{user.name} has gone to jail for the following offenses:\n"
for offenseName in rapsheet.keys():
offenseCount = rapsheet.get(offenseName)
returnString += offenseName + ", " + offenseCount + " " + getCountString(offenseCount) + "\n";
return returnString
# l18n nightmare, nice
def getCountString(number):
if number == 1:
return "count"
else:
return "counts"
@bot.event
async def on_ready():
print(f'{bot.user} is online.')
if len(sys.argv) != 2:
print("You need to provide the bot token when you startup the bot")
exit()
async def debugLogResultOrError(ctx, resultOrError):
message = f"Succeeded: {resultOrError.isSuccess()}"
if resultOrError.result != None:
message += "\n"
message += f"result: {json.dumps(resultOrError.result)}"
if resultOrError.error != None:
message += "\n"
message += f"error: {resultOrError.error.status} {resultOrError.error.message}"
await ctx.respond(message)
botToken = sys.argv[1]
bot.run(botToken)