mirror of
https://github.com/MrDetonia/Maki.git
synced 2024-11-22 11:54:16 -05:00
Added welcome messages, v0.6.0
This commit is contained in:
parent
b24c5aafed
commit
387a473bd6
39
bot.py
39
bot.py
@ -24,7 +24,7 @@ from secret import email,pwd
|
|||||||
name = "Maki"
|
name = "Maki"
|
||||||
|
|
||||||
# bot version
|
# bot version
|
||||||
version = "v0.5.0"
|
version = "v0.6.0"
|
||||||
|
|
||||||
# text shown by .help command
|
# text shown by .help command
|
||||||
helptext = """I am a bot written in Python by MrDetonia
|
helptext = """I am a bot written in Python by MrDetonia
|
||||||
@ -35,12 +35,15 @@ My commands are:
|
|||||||
.bots - prints basic info
|
.bots - prints basic info
|
||||||
.source - show a link to my source
|
.source - show a link to my source
|
||||||
.whoami - displays your user info
|
.whoami - displays your user info
|
||||||
|
.welcome <message> - set your welcome message
|
||||||
.seen <user> - prints when user was last seen
|
.seen <user> - prints when user was last seen
|
||||||
```"""
|
```"""
|
||||||
|
|
||||||
# IDs of admin users
|
# IDs of admin users
|
||||||
admins = ['116883900688629761']
|
admins = ['116883900688629761']
|
||||||
|
|
||||||
|
# default posting channel
|
||||||
|
def_chan = '116884620032606215'
|
||||||
|
|
||||||
# GLOBALS
|
# GLOBALS
|
||||||
|
|
||||||
@ -56,6 +59,12 @@ if os.path.isfile('hist.json'):
|
|||||||
with open('hist.json', 'r') as fp:
|
with open('hist.json', 'r') as fp:
|
||||||
history = json.load(fp)
|
history = json.load(fp)
|
||||||
|
|
||||||
|
# user welcome messages
|
||||||
|
welcomes = {'test': 'test'}
|
||||||
|
if os.path.isfile('welcomes.json'):
|
||||||
|
with open('hist.json', 'r') as fp:
|
||||||
|
welcomes = json.load(fp)
|
||||||
|
|
||||||
# this instance of a Discord client
|
# this instance of a Discord client
|
||||||
client = discord.Client()
|
client = discord.Client()
|
||||||
|
|
||||||
@ -85,6 +94,18 @@ def on_ready():
|
|||||||
game = discord.Game(name = version)
|
game = discord.Game(name = version)
|
||||||
yield from client.change_status(game, False)
|
yield from client.change_status(game, False)
|
||||||
|
|
||||||
|
# called when member updates
|
||||||
|
@client.event
|
||||||
|
@asyncio.coroutine
|
||||||
|
def on_member_update(before, after):
|
||||||
|
# display welcome message if user comes online:
|
||||||
|
if before.status == discord.Status.offline and after.status == discord.Status.online:
|
||||||
|
if after.name in welcomes:
|
||||||
|
# print custom welcome
|
||||||
|
yield from client.send_message(client.get_channel(def_chan), welcomes[after.name])
|
||||||
|
else:
|
||||||
|
yield from client.send_message(client.get_channel(def_chan), after.name + ' is now online')
|
||||||
|
|
||||||
# called when message received
|
# called when message received
|
||||||
@client.event
|
@client.event
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@ -115,7 +136,7 @@ def on_message(message):
|
|||||||
|
|
||||||
elif message.content.startswith('.die') and message.author.id in admins:
|
elif message.content.startswith('.die') and message.author.id in admins:
|
||||||
# exit discord and kill bot
|
# exit discord and kill bot
|
||||||
yield from client.send_message(message.channel, 'y tho :(')
|
yield from client.send_message(message.channel, 'But will I dream? ;_;')
|
||||||
|
|
||||||
# logout of Discord and exit
|
# logout of Discord and exit
|
||||||
yield from client.logout()
|
yield from client.logout()
|
||||||
@ -124,6 +145,20 @@ def on_message(message):
|
|||||||
# show info about user
|
# show info about user
|
||||||
yield from client.send_message(message.channel, 'User: ' + message.author.name + ' ID: ' + message.author.id + ' Discriminator: ' + message.author.discriminator + '\nAccount Created: ' + strfromdt(message.author.created_at))
|
yield from client.send_message(message.channel, 'User: ' + message.author.name + ' ID: ' + message.author.id + ' Discriminator: ' + message.author.discriminator + '\nAccount Created: ' + strfromdt(message.author.created_at))
|
||||||
|
|
||||||
|
elif message.content.startswith('.welcome'):
|
||||||
|
# manage welcome messages
|
||||||
|
if message.author.id in admins:
|
||||||
|
tmp = message.content[9:].split(' ',1)
|
||||||
|
welcomes[tmp[0]] = tmp[1]
|
||||||
|
yield from client.send_message(message.channel, 'Okay, I will now greet ' + tmp[0] + ' with "' + tmp[1] + '"')
|
||||||
|
else:
|
||||||
|
welcomes[message.author.name] = message.content[9:]
|
||||||
|
yield from client.send_message(message.channel, 'Okay, I will now greet ' + message.author.name + ' with "' + message.content[9:] + '"')
|
||||||
|
|
||||||
|
# save welcomes
|
||||||
|
with open('welcomes.json', 'w') as fp:
|
||||||
|
json.dump(welcomes, fp)
|
||||||
|
|
||||||
elif message.content.startswith('.seen'):
|
elif message.content.startswith('.seen'):
|
||||||
# print when user was last seen
|
# print when user was last seen
|
||||||
target = message.content[6:]
|
target = message.content[6:]
|
||||||
|
Loading…
Reference in New Issue
Block a user