forked from NinjaPanda263/Roc-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
executable file
·96 lines (82 loc) · 3.39 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import logging
import discord
import discord.ext.commands
from discord.ext import commands
from discord.utils import get
import settings
import os
import sys, traceback
logger = logging.getLogger('discord')
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w')
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(handler)
def get_prefix(bot, message):
"""A callable Prefix for our bot. This could be edited to allow per server prefixes."""
prefixes = ['!']
# If we are in a guild, we allow for the user to mention us or use any of the prefixes in our list.
return commands.when_mentioned_or(*prefixes)(bot, message)
initial_extensions = ['cogs.simple',
'cogs.invader',
'cogs.daily',
'cogs.img',
'cogs.ship',
'cogs.owner',
'cogs.price',
'cogs.apex'
]
bot = commands.Bot(
command_prefix=get_prefix,
description='Phoenix 2 iOS information bot',
# Jinbe current ID, change to yours when running
owner_id=197895310108917762)
# Here we load our extensions(cogs) listed above in [initial_extensions].
if __name__ == '__main__':
for extension in initial_extensions:
try:
bot.load_extension(extension)
except Exception as e:
print(f'Failed to load extension {extension}.', file=sys.stderr)
traceback.print_exc()
@bot.event
async def on_ready():
"""http://discordpy.readthedocs.io/en/rewrite/api.html#discord.on_ready"""
print('We have logged in as {0.user}'.format(bot))
# Changes our bots Playing Status. type=1(streaming) for a standard game you could remove type and url.
game = discord.Game("Phoenix II")
await bot.change_presence(status=discord.Status.online, activity=game)
print(f'Successfully logged in and booted...!')
################################################################
#### Bot commands ####
################################################################
# If a message receives the :el: emoji, then the bot should add it's own :el: reaction
@bot.event
async def on_reaction_add(reaction, user):
# we do not want the bot to react to its own reaction
if user == bot.user:
return
elif str(reaction.emoji) == "<:el:373097097727049728>":
emoji = get(bot.emojis, name='el')
await reaction.message.add_reaction(emoji)
return
elif str(reaction.emoji) == "<:ogonisfine:583241232768303105>":
emoji = get(bot.emojis, name='ogonisfine')
await reaction.message.add_reaction(emoji)
return
# If someone uses the :el: emoji in a message then the bot should add it's own :el: reaction to the message.
@bot.event
async def on_message(message):
await bot.process_commands(message)
# we do not want the bot to reply to itself
if message.author == bot.user:
return
if ':el:' in message.content:
emoji = get(bot.emojis, name='el')
await message.add_reaction(emoji)
elif 'ogon is fine' in message.content:
emoji = get(bot.emojis, name='ogonisfine')
await message.add_reaction(emoji)
return
bot.run(settings.discordkey)