-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
54 lines (40 loc) · 1.11 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import re
import sys
import discord # type: ignore
APP_TOKEN = "JUSTSAYSINMICEBOT_TOKEN"
INMICE_PATTERN = re.compile(r"in.*mice", re.IGNORECASE)
client = discord.Client()
class NoAppToken(Exception):
pass
@client.event
async def on_ready() -> None:
print(f"We have logged in as {client.user}")
@client.event
async def on_message(message: discord.Message) -> None:
if message.author == client.user:
return
if INMICE_PATTERN.search(message.content):
await message.channel.send("IN MICE")
def main() -> None:
def _app_token() -> str:
try:
token = os.environ[APP_TOKEN]
assert token
except (KeyError, AssertionError) as e:
raise NoAppToken
return token
try:
token = _app_token()
except NoAppToken:
sys.exit(
(
"Please expose Discord app token as env var {APP_TOKEN};"
" if using docker, cp template.env .env, fill in token"
)
)
client.run(token)
if __name__ == "__main__":
main()