Files
Gwendolyn/Gwendolyn.py
Nikolaj Danger be55f8c564 Minor changes
2020-03-25 11:39:29 +01:00

182 lines
8.7 KiB
Python

# -*- coding: utf-8 -*-
import discord
import asyncio
import pickle
import time
import logging
import codecs
import funcs
logging.basicConfig(filename="gwendolyn.log", level=logging.INFO)
with open("token.txt","r") as f:
token = f.read().replace("\n","")
client = discord.Client()
@client.event
async def on_ready():
localtime = time.asctime( time.localtime(time.time()) )
print(localtime)
print("Logged in as")
print(client.user.name)
print(client.user.id)
print("-----------")
logging.info("\n-----------\n"+localtime+"\nLogged in")
game = discord.Game("Some weeb shit")
await client.change_presence(activity=game)
@client.event
async def on_message(message):
if message.content.lower().startswith("!help"):
localtime = time.asctime( time.localtime(time.time()) )
print("\n"+localtime+"\n"+message.author.name+" ran !help")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !help")
with codecs.open("resources/help.txt",encoding="utf-8") as f:
text = f.read()
print(text)
em = discord.Embed(title = "Help", description = text,colour = 0x59f442)
await message.channel.send(embed = em)
elif message.content.lower().startswith("!stop"):
await client.logout()
elif message.content.lower().startswith("!hello"):
localtime = time.asctime( time.localtime(time.time()) )
print("\n"+localtime+"\n"+message.author.name+" ran !hello")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !hello")
await message.channel.send(funcs.helloFunc(message.author.name))
elif message.content.lower().startswith("!roll"):
localtime = time.asctime( time.localtime(time.time()) )
print("\n"+localtime+"\n"+message.author.name+" ran !roll")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !roll")
if message.content.lower() == "!roll" or message.content.lower() == "!roll ":
await message.channel.send(funcs.roll_dice(message.author.name))
else:
await message.channel.send(funcs.roll_dice(message.author.name, message.content.lower().replace("!roll","")))
elif message.content.lower().startswith("!spell "):
localtime = time.asctime( time.localtime(time.time()) )
print("\n"+localtime+"\n"+message.author.name+" ran !spell")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !spell")
await message.channel.send(funcs.spellFunc(message.content))
elif message.content.lower().startswith("!monster "):
localtime = time.asctime( time.localtime(time.time()) )
print("\n"+localtime+"\n"+message.author.name+" ran !monster")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !monster")
title, text1, text2, text3, text4, text5 = funcs.monsterFunc(message.content)
em1 = discord.Embed(title = title, description = text1, colour=0xDEADBF)
# Sends the received information. Seperates into seperate messages if
# there is too much text
await message.channel.send(embed = em1)
if text2 != "":
if len(text2) < 2048:
em2 = discord.Embed(title = "Special Abilities", description = text2, colour=0xDEADBF)
await message.channel.send(embed = em2)
else:
em2 = discord.Embed(title = "Special Abilities", description = text2[:2048], colour=0xDEADBF)
await message.channel.send(embed = em2)
em2_2 = discord.Embed(title = "", description = text2[2048:], colour=0xDEADBF)
await message.channel.send(embed = em2_2)
if text3 != "":
if len(text3) < 2048:
em3 = discord.Embed(title = "Actions", description = text3, colour=0xDEADBF)
await message.channel.send(embed = em3)
else:
em3 = discord.Embed(title = "Actions", description = text3[:2048], colour=0xDEADBF)
await message.channel.send(embed = em3)
em3_2 = discord.Embed(title = "", description = text3[2048:], colour=0xDEADBF)
await message.channel.send(embed = em3_2)
if text4 != "":
if len(text4) < 2048:
em4 = discord.Embed(title = "Reactions", description = text4, colour=0xDEADBF)
await message.channel.send(embed = em4)
else:
em4 = discord.Embed(title = "Reactions", description = text4[:2048], colour=0xDEADBF)
await message.channel.send(embed = em4)
em4_2 = discord.Embed(title = "", description = text4[2048:], colour=0xDEADBF)
await message.channel.send(embed = em4_2)
if text5 != "":
if len(text5) < 2048:
em5 = discord.Embed(title = "Legendary Actions", description = text5, colour=0xDEADBF)
await message.channel.send(embed = em5)
else:
em5 = discord.Embed(title = "Legendary Actions", description = text5[:2048], colour=0xDEADBF)
await message.channel.send(embed = em5)
em5_2 = discord.Embed(title = "", description = text5[2048:], colour=0xDEADBF)
await message.channel.send(embed = em5_2)
elif message.content.lower().startswith("!map"):
localtime = time.asctime( time.localtime(time.time()) )
print("\n"+localtime+"\n"+message.author.name+" ran !map")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !map")
await message.channel.send("https://i.imgur.com/diMXXJs.jpg")
elif message.content.lower().startswith("!image"):
localtime = time.asctime( time.localtime(time.time()) )
print("\n"+localtime+"\n"+message.author.name+" ran !image")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !image")
await message.channel.send(funcs.imageFunc())
elif message.content.lower().startswith("!movie"):
localtime = time.asctime( time.localtime(time.time()) )
print("\n"+localtime+"\n"+message.author.name+" ran !movie")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !movie")
async with message.channel.typing():
title, plot, cover, cast = funcs.movieFunc()
if title == "error":
await message.channel.send("An error occurred. Try again")
else:
embed = discord.Embed(title=title, description=plot, color=0x24ec19)
embed.set_thumbnail(url=cover)
embed.add_field(name="Cast", value=cast,inline = True)
await message.channel.send(embed = embed)
elif message.content.lower().startswith("!name"):
localtime = time.asctime( time.localtime(time.time()) )
print("\n"+localtime+"\n"+message.author.name+" ran !name")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !name")
await message.channel.send(funcs.nameGen())
elif message.content.lower().startswith("!tavern"):
localtime = time.asctime( time.localtime(time.time()) )
print("\n"+localtime+"\n"+message.author.name+" ran !tavern")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !tavern")
await message.channel.send(funcs.tavernGen())
elif message.content.lower().startswith("!game "):
gamePlaying = funcs.cap(message.content.lower().replace("!game ",""))
localtime = time.asctime( time.localtime(time.time()) )
print("\n"+localtime+"\n"+message.author.name+" ran !game, changing the game to '"+gamePlaying+"'")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !game, changing the game to '"+gamePlaying+"'")
game = discord.Game(gamePlaying)
await client.change_presence(activity=game)
elif message.content.lower().startswith("!swroll"):
localtime = time.asctime( time.localtime(time.time()) )
print("\n"+localtime+"\n"+message.author.name+" ran !swroll")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !swroll")
command = funcs.cap(message.content.lower().replace("!swroll",""))
await message.channel.send(funcs.parseRoll(message.author.name,command))
elif message.content.lower().startswith("!swchar"):
localtime = time.asctime(time.localtime(time.time()))
print("\n"+localtime+"\n"+message.author.name+" ran !swchar")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !swchar")
command = funcs.cap(message.content.lower().replace("!swchar",""))
title, desc = funcs.parseChar(message.author.name,command)
if title != "":
em1 = discord.Embed(title = title, description = desc, colour=0xDEADBF)
await message.channel.send(embed = em1)
else:
await message.channel.send(desc)
client.run(token)