-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
116 lines (85 loc) · 3.01 KB
/
script.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
import os
import discord
from dotenv import load_dotenv
from discord.ext import commands
from grapher import Map
# top secret
load_dotenv()
token = os.getenv('TOKEN')
# map image path
image_path = "graph.png"
# intents
intents = discord.Intents.default()
intents.message_content = True
intents.messages = True
intents.guilds = True
intents.guild_messages = True
intents.presences = True
bot = commands.Bot(command_prefix=["!","stt "], intents=intents)
# contains Map objects
mapList = []
# Custom HelpCommand
class CustomHelpCommand(commands.HelpCommand):
async def send_bot_help(self, mapping):
embed = discord.Embed(title="Bot Commands",description="Spill the tea in ur friend group!\n`The bot will map the 'connections' between ppl.\nif the value between 2 ppl is 1, it is 1 sided,\notherwise, if it is 2, its mu2al!`\n\n`bot prefix: '!' or 'stt '`", color=discord.Color.blue())
instruction = "`type stt like [mention]`"
embed.add_field(name="How to use !like", value=instruction, inline=False)
commands = [
{"name": "like", "brief": "Submit your tea (smone u like) :)"},
{"name": "show", "brief": "Displays map."},
{"name": "reset", "brief": "Resets the image."},
{"name": "help", "brief": "Shows the list of available commands."}
]
command_list = "\n".join([f"`{cmd['name']}`: {cmd['brief']}" for cmd in commands])
embed.add_field(name="Commands", value=command_list, inline=False)
await self.get_destination().send(embed=embed)
# Set the custom help command
bot.help_command = CustomHelpCommand()
@bot.event
async def on_ready():
print(f"Bot is ready. Logged in as {bot.user}")
@bot.event
async def on_message(message):
if message.author != bot.user:
await bot.process_commands(message)
@bot.command(brief="submit your crush")
async def like(ctx, member: discord.Member):
global mapList
# Map object for the current server
mapInstance = findMap(ctx)
person1 = ctx.author.name
person2 = member.name
mapInstance.connect(person1,person2)
# load image
image = discord.File(image_path)
await ctx.send(file=image)
@bot.command()
async def show(ctx):
mapInstance = findMap(ctx)
mapInstance.drawMap()
image = discord.File(image_path)
await ctx.send(file=image)
@bot.command(brief="reset the image")
async def reset(ctx):
mapInstance = findMap(ctx)
if os.path.exists(image_path):
mapInstance.reset()
await ctx.send("map has been reset")
else:
await ctx.send(f"{image_path} does not exist.")
# returns a Map object
# if there isnt one for the server, create a new Map object
def findMap(ctx):
global mapList
server = ctx.guild
# Map Object
mapInstance = None
for mapObj in mapList:
if mapObj.serverName == server:
mapInstance = mapObj
break
if mapInstance is None:
mapInstance = Map(server)
mapList.append(mapInstance)
return mapInstance
bot.run(token)