-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
107 lines (83 loc) · 3.02 KB
/
bot.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
# This example requires the 'message_content' intent.
import discord
from dotenv import load_dotenv
import os
import re
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
ignore_roles = True
ignored_roles = ["The Crew", "Port Engineers","Administrator","Port Cadets","Developer","Moderator"]
if not ignore_roles:
ignored_roles = []
common_keywords = ["port","ported","porting","want","coming","available","about","regarding","portmaster","game","uses","made","written","programmed"]
listening_channels = ["bot-submersible","💡|suggestion-talk"]
generic_reponse = "This is an automated response. Please check the [new-suggestion](https://discord.com/channels/1122861252088172575/1232622554984878120) channel for more information on porting."
slash_commands = {
"/portchart": {
"response": "Here is the portability chart https://raw.githubusercontent.com/PortsMaster/Port-Bot/main/Portmaster_chart.webp"
},
"/log": {
"response": "Every port has a log.txt generated in `ports/{portfolder}`, please drag and drop it to discord for help."
}
}
response_mappings = [
{
"name": "PokeMMO",
"type": "text",
"keywords": ["pokemmo","pokemon mmo"],
"response": "PokeMMO can't be ported at this time."
},
{
"name": "Unity",
"type": "text",
"keywords": ["unity"],
"response": "Games using Unity can't be ported at this time."
},
{
"name": "San Andreas",
"type": "text",
"keywords": ["andreas","san andreas"],
"response": "Grand Theft Auto: San Andreas can't be ported at this time."
}
]
load_dotenv()
def check_command(message):
message = message.lower()
for command in slash_commands:
if message == command:
return(slash_commands[command]["response"])
def parseMessage(message):
message = message.lower()
is_common = False
for common in common_keywords:
if common in message:
is_common = True
break
if is_common:
for mapping in response_mappings:
for keyword in mapping["keywords"]:
x = re.compile(r'\b%s\b' % keyword, re.I)
if x.search(message):
response = mapping["response"] + "\n\n" + generic_reponse
return(response)
return(False)
@client.event
async def on_ready():
print(f'We have logged in as {client.user}')
@client.event
async def on_message(message):
if message.author == client.user:
return
response = check_command(message.content)
if response:
await message.reply(response)
if hasattr(message.author,"roles"):
for role in message.author.roles:
if role.name in ignored_roles:
return
#if str(message.channel) in listening_channels:
response = parseMessage(message.content)
if response:
await message.reply(response)
client.run(os.getenv('BOT_TOKEN'))