forked from Vanjaman/Konglig-Drifvare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
97 lines (78 loc) · 3.32 KB
/
main.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
import os
import asyncio
import random
import discord
import subprocess
from discord.ext import commands
import helper_functions
import keep_alive
from helper_functions import scareface
from helper_functions import offset_list
from helper_functions import mentions
"""Denna modul är main modulen som faktiskt hanterar discord delen av boten"""
token = os.environ['TOKEN']
bot = commands.Bot(command_prefix='$')
@bot.command()
async def ping(ctx):
"""Kommando som visar bottens svarstid"""
embed = discord.Embed(
title="Pong!",
description=("Det Kongliga Drifveriet svarar vanligtvis snabbare än ljusets hastighet, "
"men för att ~~nØllans~~ ettans synapser skall hänga med "
f"har det Kongliga Drifveriet beslutat att svara på {round(bot.latency*1000)} millisekunder!")
)
embed.set_thumbnail(
url="https://cdn.discordapp.com/attachments/572159063505371137/900800963651199086/drifveriet.png")
await ctx.send(embed=embed)
@bot.event
async def on_ready():
"""Skriver ut att botten är online"""
print("Drifvare online.")
@bot.event
async def on_message(message):
"""Hanterar meddelander reaktioner som triggar boten"""
global mentions
if message.author == bot.user:
return
mention = f'<@!{bot.user.id}>'
if mention in message.content:
mentions += 1
else:
mentions = 0
if mentions == 3 or message.content.count(mention) == 3:
message = await message.channel.send(scareface)
for _ in range(4):
await message.edit(content="\n".join(
[random.choice(offset_list) * " " + x for x in scareface.split("\n")]))
await asyncio.sleep(random.choice([0, 0, 0.25, 0.5, 1]))
await message.edit(content=scareface)
mentions = 0
elif mention in message.content:
await message.channel.send("Drifveriet ser ~~nØllan~~ ettan.")
elif "en hel del" in message.content.lower():
messageArr = message.content.split(" ")
index = messageArr.index("del")
if index < len(messageArr)-1:
m = messageArr[index+1].upper()
else:
m = "PENGAR" #Default om det inte är något efter 'del'
await message.channel.send("mmmmMMM**" + m + "**")
elif any(x in message.content.lower() for x in ("pit bull", "pitbull")):
await message.channel.send("dale")
elif "betong" in message.content.lower():
p = subprocess.Popen("cat *.py | wc -l", shell=True, stdout=subprocess.PIPE)
(rows, err) = p.communicate()
rows = int(rows)
await message.channel.send(
(f"Bakom 30 meter betong, 5 blyinfattade pansardörrar och {rows} rader pythonkod har det"
" Kongliga Drifveriet observerat ~~nØllans~~ ettans discordkunskaper."
" Det har *inte* gått bra. **Inte så bra alls!!!**"
" ***Att säga att ettan är bra på discord är lite som att tro att drifveriet inte kan höra vad du tänker just nu.***"
)
)
elif random.randint(0, 420) == 69:
if message.channel.category.name not in ("═════ Kurskanaler ═════", "═══ \"Avslutade\" Kurser ══"):
await helper_functions.jubla(message)
await bot.process_commands(message)
keep_alive.keep_alive()
bot.run(token)