moved functions to essentials.py and runescape.py
This commit is contained in:
parent
082caff2b7
commit
c380d8f1a0
4 changed files with 220 additions and 159 deletions
185
plugins/essentials.py
Normal file
185
plugins/essentials.py
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
#plugin for sparkytron 3000
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
|
||||
from discord.ext import commands
|
||||
|
||||
async def handle_error(error):
|
||||
print(error)
|
||||
current_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
||||
log_line = current_time + ': ' + str(error) + '\n'
|
||||
with open("databases/error_log.txt", 'a') as f:
|
||||
f.write(log_line)
|
||||
return error
|
||||
|
||||
def create_channel_config(filepath):
|
||||
config_dict = {
|
||||
"personality":"average",
|
||||
"channel_topic":"casual",
|
||||
"chat_enabled":False,
|
||||
"commands_enabled":True,
|
||||
"chat_history_len":5,
|
||||
"look_at_images":False,
|
||||
"react_to_msgs":False,
|
||||
"ftp_enabled":False
|
||||
}
|
||||
|
||||
with open(filepath,"w") as f:
|
||||
json.dump(config_dict,f)
|
||||
print("Wrote config variables to file.")
|
||||
|
||||
async def get_channel_config(channel_id):
|
||||
filepath = "channels/config/{0}.json".format(str(channel_id))
|
||||
if not os.path.exists(filepath):
|
||||
create_channel_config(filepath)
|
||||
with open(filepath, "r") as f:
|
||||
config_dict = json.loads(f.readline())
|
||||
return config_dict
|
||||
|
||||
def edit_channel_config(channel_id, key, value):
|
||||
config_file = "channels/config/" + str(channel_id) + ".json"
|
||||
with open(config_file, 'r') as f:
|
||||
config_data = json.load(f)
|
||||
config_data[key] = value
|
||||
with open(config_file, "w") as f:
|
||||
json.dump(config_data, f)
|
||||
|
||||
@commands.command(
|
||||
description="View Images",
|
||||
help="Enable or disable bot viewing images in this channel. Usage !viewimages (enable|disable)",
|
||||
brief="Enable or disable bot viewing images"
|
||||
)
|
||||
async def view_images(ctx, message):
|
||||
if "enable" in message:
|
||||
edit_channel_config(ctx.channel.id, "look_at_images", True)
|
||||
await ctx.send("Viewing Enabled")
|
||||
elif "disable" in message:
|
||||
edit_channel_config(ctx.channel.id, "look_at_images", False)
|
||||
await ctx.send("Viewing Disabled")
|
||||
else:
|
||||
await ctx.send("Usage: !viewimages (enable|disable)")
|
||||
|
||||
|
||||
@commands.command(
|
||||
description="FTP",
|
||||
help="Enable or disable bot FTP to phixxy.com in this channel. Usage !ftp (enable|disable)",
|
||||
brief="Enable or disable uploading to web"
|
||||
)
|
||||
async def ftp(ctx, message):
|
||||
if "enable" in message:
|
||||
edit_channel_config(ctx.channel.id, "ftp_enabled", True)
|
||||
await ctx.send("FTP Enabled")
|
||||
elif "disable" in message:
|
||||
edit_channel_config(ctx.channel.id, "ftp_enabled", False)
|
||||
await ctx.send("FTP Disabled")
|
||||
else:
|
||||
await ctx.send("Usage: !ftp (enable|disable)")
|
||||
|
||||
@commands.command(
|
||||
description="Personality",
|
||||
help="Set the personality of the bot. Usage: !personality (personality)",
|
||||
brief="Set the personality"
|
||||
)
|
||||
async def personality(ctx):
|
||||
personality_type = ctx.message.content.split(" ", maxsplit=1)[1]
|
||||
edit_channel_config(ctx.channel.id, "personality", personality_type)
|
||||
await ctx.send("Personality changed to " + personality_type)
|
||||
|
||||
@commands.command(
|
||||
description="Commands",
|
||||
help="Enable or disable bot commands in this channel. Usage !enable_commands (enable|disable)",
|
||||
brief="Enable or disable bot commands"
|
||||
)
|
||||
async def enable_commands(ctx, message):
|
||||
if "disable" in message or "false" in message:
|
||||
edit_channel_config(ctx.channel.id, "commands_enabled", False)
|
||||
await ctx.send("Commands Disabled")
|
||||
else:
|
||||
edit_channel_config(ctx.channel.id, "commands_enabled", True)
|
||||
await ctx.send("Commands Enabled")
|
||||
|
||||
@commands.command(
|
||||
description="Topic",
|
||||
help="Set the channel topic for the bot. Usage: !topic (topic)",
|
||||
brief="Set channel topic"
|
||||
)
|
||||
async def topic(ctx, channel_topic):
|
||||
edit_channel_config(ctx.channel.id, "channel_topic", channel_topic)
|
||||
await ctx.send("Topic changed to " + channel_topic)
|
||||
|
||||
@commands.command(
|
||||
description="Chat",
|
||||
help="Enable or disable bot chat in this channel. Usage !chat (enable|disable)",
|
||||
brief="Enable or disable bot chat"
|
||||
)
|
||||
async def chat(ctx, message):
|
||||
if "enable" in message:
|
||||
edit_channel_config(ctx.channel.id, "chat_enabled", True)
|
||||
await ctx.send("Chat Enabled")
|
||||
elif "disable" in message:
|
||||
edit_channel_config(ctx.channel.id, "chat_enabled", False)
|
||||
await ctx.send("Chat Disabled")
|
||||
else:
|
||||
await ctx.send("Usage: !chat (enable|disable)")
|
||||
|
||||
@commands.command(
|
||||
description="Reactions",
|
||||
help="Enable or disable bot reactions in this channel. Usage !reactions (enable|disable)",
|
||||
brief="Enable or disable bot reactions"
|
||||
)
|
||||
async def reactions(ctx, message):
|
||||
if "enable" in message:
|
||||
edit_channel_config(ctx.channel.id, "react_to_msgs", True)
|
||||
await ctx.send("Reactions Enabled")
|
||||
elif "disable" in message:
|
||||
edit_channel_config(ctx.channel.id, "react_to_msgs", False)
|
||||
await ctx.send("Reactions Disabled")
|
||||
else:
|
||||
await ctx.send("Usage: !reactions (enable|disable)")
|
||||
|
||||
@commands.command(
|
||||
description="Feature",
|
||||
help="Suggest a feature. Usage: !feature (feature)",
|
||||
brief="Suggest a feature"
|
||||
)
|
||||
async def feature(ctx):
|
||||
try:
|
||||
feature = ctx.message.content.split(" ", maxsplit=1)[1]
|
||||
with open("features.txt",'a') as f:
|
||||
f.writelines('\n' + feature)
|
||||
await ctx.send("Added " + feature)
|
||||
except Exception as error:
|
||||
await handle_error(error)
|
||||
|
||||
with open("features.txt",'r') as f:
|
||||
features = f.read()
|
||||
await ctx.send(features)
|
||||
|
||||
@commands.command(
|
||||
description="Errors",
|
||||
help="Shows the last errors that were logged.",
|
||||
brief="Display Errors"
|
||||
)
|
||||
async def errors(ctx, amount="5"):
|
||||
output = ""
|
||||
amount = int(amount)
|
||||
try:
|
||||
with open("databases/error_log.txt", 'r') as f:
|
||||
for line in (f.readlines() [-amount:]):
|
||||
output += line
|
||||
await ctx.send(output)
|
||||
except Exception as error:
|
||||
await handle_error(error)
|
||||
|
||||
|
||||
async def setup(bot):
|
||||
bot.add_command(feature)
|
||||
bot.add_command(reactions)
|
||||
bot.add_command(chat)
|
||||
bot.add_command(topic)
|
||||
bot.add_command(enable_commands)
|
||||
bot.add_command(personality)
|
||||
bot.add_command(ftp)
|
||||
bot.add_command(view_images)
|
||||
bot.add_command(errors)
|
||||
|
|
@ -271,4 +271,4 @@ async def pokedex(ctx):
|
|||
|
||||
async def setup(bot):
|
||||
bot.add_command(pokedex)
|
||||
bot.add_command(pokemon)
|
||||
bot.add_command(pokemon)
|
||||
|
|
|
|||
31
plugins/runescape.py
Normal file
31
plugins/runescape.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#sparkytron3000 plugin
|
||||
from discord.ext import commands
|
||||
|
||||
@commands.command(
|
||||
description="RSGP",
|
||||
help="Uses probably outdated information to calculate how much rsgp is worth in usd. Usage: !rsgp (amount)",
|
||||
brief="Runescape gold to usd"
|
||||
)
|
||||
async def rsgp(ctx, amount):
|
||||
output = ""
|
||||
cost_per_bil = 25.50 #1b rsgp to usd
|
||||
cost_per_bil_os = 210
|
||||
gold_per_bond = 70000000
|
||||
gold_per_bond_os = 7000000
|
||||
cost_per_bond = 8 #dollars usd
|
||||
bondcost = (int(amount)/gold_per_bond) * cost_per_bond
|
||||
rwtcost = (int(amount) * cost_per_bil / 1000000000)
|
||||
dollar_gp = (int(amount)*1000000000)/cost_per_bil
|
||||
osbondcost = (int(amount)/gold_per_bond_os) * cost_per_bond
|
||||
osrwtcost = (int(amount) * cost_per_bil_os / 1000000000)
|
||||
osdollar_gp = (int(amount)*1000000000)/cost_per_bil_os
|
||||
output += str(amount) + ' rs3 gp would cost: $' + str(round(rwtcost,2)) + " (RWT)\n"
|
||||
output += str(amount) + ' osrs gp would cost: $' + str(round(osrwtcost,2)) + " (RWT)\n"
|
||||
output += str(amount) + ' rs3 gp would cost: $' + str(round(bondcost,2)) + " (Bonds)\n"
|
||||
output += str(amount) + ' osrs gp would cost: $' + str(round(osbondcost,2)) + " (Bonds)\n"
|
||||
output += str(amount) + ' dollars spent on rs3 gp would be: ' + str(round(dollar_gp,2)) + " (RS3 GP)\n"
|
||||
output += str(amount) + ' dollars spent on osrs gp would be: ' + str(round(osdollar_gp,2)) + " (OSRS GP)\n"
|
||||
await ctx.send(output)
|
||||
|
||||
async def setup(bot):
|
||||
bot.add_command(rsgp)
|
||||
|
|
@ -148,13 +148,13 @@ async def answer_question(topic, model="gpt-3.5-turbo"):
|
|||
return await handle_error(error)
|
||||
|
||||
|
||||
def edit_channel_config(channel_id, key, value):
|
||||
'''def edit_channel_config(channel_id, key, value):
|
||||
config_file = "channels/config/" + str(channel_id) + ".json"
|
||||
with open(config_file, 'r') as f:
|
||||
config_data = json.load(f)
|
||||
config_data[key] = value
|
||||
with open(config_file, "w") as f:
|
||||
json.dump(config_data, f)
|
||||
json.dump(config_data, f)'''
|
||||
|
||||
async def react_to_msg(ctx, react):
|
||||
|
||||
|
|
@ -282,9 +282,6 @@ async def task_loop():
|
|||
await meme_handler('tmp/meme/')
|
||||
await upload_ftp_ai_images('tmp/sfw/')
|
||||
|
||||
|
||||
|
||||
|
||||
#Run daily tasks
|
||||
if current_time.tm_hour == 17 and current_time.tm_min == 0 and current_time.tm_sec == 0:
|
||||
bot_stuff = bot.get_channel(544408659174883328)
|
||||
|
|
@ -362,48 +359,6 @@ async def update(ctx):
|
|||
else:
|
||||
await ctx.send("You don't have permission to do this.")
|
||||
|
||||
|
||||
@bot.command(
|
||||
description="Errors",
|
||||
help="Shows the last errors that were logged.",
|
||||
brief="Display Errors"
|
||||
)
|
||||
async def errors(ctx, amount="5"):
|
||||
output = ""
|
||||
amount = int(amount)
|
||||
try:
|
||||
with open("databases/error_log.txt", 'r') as f:
|
||||
for line in (f.readlines() [-amount:]):
|
||||
output += line
|
||||
await ctx.send(output)
|
||||
except Exception as error:
|
||||
await handle_error(error)
|
||||
|
||||
@bot.command(
|
||||
description="RSGP",
|
||||
help="Uses probably outdated information to calculate how much rsgp is worth in usd. Usage: !rsgp (amount)",
|
||||
brief="Runescape gold to usd"
|
||||
)
|
||||
async def rsgp(ctx, amount):
|
||||
output = ""
|
||||
cost_per_bil = 25.50 #1b rsgp to usd
|
||||
cost_per_bil_os = 210
|
||||
gold_per_bond = 70000000
|
||||
gold_per_bond_os = 7000000
|
||||
cost_per_bond = 8 #dollars usd
|
||||
bondcost = (int(amount)/gold_per_bond) * cost_per_bond
|
||||
rwtcost = (int(amount) * cost_per_bil / 1000000000)
|
||||
dollar_gp = (int(amount)*1000000000)/cost_per_bil
|
||||
osbondcost = (int(amount)/gold_per_bond_os) * cost_per_bond
|
||||
osrwtcost = (int(amount) * cost_per_bil_os / 1000000000)
|
||||
osdollar_gp = (int(amount)*1000000000)/cost_per_bil_os
|
||||
output += str(amount) + ' rs3 gp would cost: $' + str(round(rwtcost,2)) + " (RWT)\n"
|
||||
output += str(amount) + ' osrs gp would cost: $' + str(round(osrwtcost,2)) + " (RWT)\n"
|
||||
output += str(amount) + ' rs3 gp would cost: $' + str(round(bondcost,2)) + " (Bonds)\n"
|
||||
output += str(amount) + ' osrs gp would cost: $' + str(round(osbondcost,2)) + " (Bonds)\n"
|
||||
output += str(amount) + ' dollars spent on rs3 gp would be: ' + str(round(dollar_gp,2)) + " (RS3 GP)\n"
|
||||
output += str(amount) + ' dollars spent on osrs gp would be: ' + str(round(osdollar_gp,2)) + " (OSRS GP)\n"
|
||||
await ctx.send(output)
|
||||
|
||||
@bot.command(
|
||||
description="Blog",
|
||||
|
|
@ -807,92 +762,7 @@ async def website(ctx):
|
|||
except Exception as error:
|
||||
await handle_error(error)
|
||||
await ctx.send("Failed, Try again.")
|
||||
|
||||
@bot.command(
|
||||
description="Feature",
|
||||
help="Suggest a feature. Usage: !feature (feature)",
|
||||
brief="Suggest a feature"
|
||||
)
|
||||
async def feature(ctx):
|
||||
try:
|
||||
feature = ctx.message.content.split(" ", maxsplit=1)[1]
|
||||
with open("features.txt",'a') as f:
|
||||
f.writelines('\n' + feature)
|
||||
await ctx.send("Added " + feature)
|
||||
except Exception as error:
|
||||
await handle_error(error)
|
||||
|
||||
with open("features.txt",'r') as f:
|
||||
features = f.read()
|
||||
await ctx.send(features)
|
||||
|
||||
|
||||
@bot.command(
|
||||
description="Chat",
|
||||
help="Enable or disable bot chat in this channel. Usage !chat (enable|disable)",
|
||||
brief="Enable or disable bot chat"
|
||||
)
|
||||
async def chat(ctx, message):
|
||||
if "enable" in message:
|
||||
edit_channel_config(ctx.channel.id, "chat_enabled", True)
|
||||
await ctx.send("Chat Enabled")
|
||||
elif "disable" in message:
|
||||
edit_channel_config(ctx.channel.id, "chat_enabled", False)
|
||||
await ctx.send("Chat Disabled")
|
||||
else:
|
||||
await ctx.send("Usage: !chat (enable|disable)")
|
||||
|
||||
@bot.command(
|
||||
description="Reactions",
|
||||
help="Enable or disable bot reactions in this channel. Usage !reactions (enable|disable)",
|
||||
brief="Enable or disable bot reactions"
|
||||
)
|
||||
async def reactions(ctx, message):
|
||||
if "enable" in message:
|
||||
edit_channel_config(ctx.channel.id, "react_to_msgs", True)
|
||||
await ctx.send("Reactions Enabled")
|
||||
elif "disable" in message:
|
||||
edit_channel_config(ctx.channel.id, "react_to_msgs", False)
|
||||
await ctx.send("Reactions Disabled")
|
||||
else:
|
||||
await ctx.send("Usage: !reactions (enable|disable)")
|
||||
|
||||
@bot.command(
|
||||
description="View Images",
|
||||
help="Enable or disable bot viewing images in this channel. Usage !viewimages (enable|disable)",
|
||||
brief="Enable or disable bot viewing images"
|
||||
)
|
||||
async def viewimages(ctx, message):
|
||||
if "enable" in message:
|
||||
edit_channel_config(ctx.channel.id, "look_at_images", True)
|
||||
await ctx.send("Viewing Enabled")
|
||||
elif "disable" in message:
|
||||
edit_channel_config(ctx.channel.id, "look_at_images", False)
|
||||
await ctx.send("Viewing Disabled")
|
||||
else:
|
||||
await ctx.send("Usage: !viewimages (enable|disable)")
|
||||
|
||||
@bot.command(
|
||||
description="Commands",
|
||||
help="Enable or disable bot commands in this channel. Usage !enable_commands (enable|disable)",
|
||||
brief="Enable or disable bot commands"
|
||||
)
|
||||
async def enable_commands(ctx, message):
|
||||
if "disable" in message or "false" in message:
|
||||
edit_channel_config(ctx.channel.id, "commands_enabled", False)
|
||||
await ctx.send("Commands Disabled")
|
||||
else:
|
||||
edit_channel_config(ctx.channel.id, "commands_enabled", True)
|
||||
await ctx.send("Commands Enabled")
|
||||
|
||||
@bot.command(
|
||||
description="Topic",
|
||||
help="Set the channel topic for the bot. Usage: !topic (topic)",
|
||||
brief="Set channel topic"
|
||||
)
|
||||
async def topic(ctx, channel_topic):
|
||||
edit_channel_config(ctx.channel.id, "channel_topic", channel_topic)
|
||||
await ctx.send("Topic changed to " + channel_topic)
|
||||
|
||||
'''@bot.command(
|
||||
description="Python",
|
||||
|
|
@ -936,32 +806,7 @@ async def python(ctx):
|
|||
except Exception as error:
|
||||
await handle_error(error)
|
||||
await ctx.send("Usage: !python (codeblock)")'''
|
||||
|
||||
|
||||
@bot.command(
|
||||
description="FTP",
|
||||
help="Enable or disable bot FTP to phixxy.com in this channel. Usage !ftp (enable|disable)",
|
||||
brief="Enable or disable uploading to web"
|
||||
)
|
||||
async def ftp(ctx, message):
|
||||
if "enable" in message:
|
||||
edit_channel_config(ctx.channel.id, "ftp_enabled", True)
|
||||
await ctx.send("FTP Enabled")
|
||||
elif "disable" in message:
|
||||
edit_channel_config(ctx.channel.id, "ftp_enabled", False)
|
||||
await ctx.send("FTP Disabled")
|
||||
else:
|
||||
await ctx.send("Usage: !ftp (enable|disable)")
|
||||
|
||||
@bot.command(
|
||||
description="Personality",
|
||||
help="Set the personality of the bot. Usage: !personality (personality)",
|
||||
brief="Set the personality"
|
||||
)
|
||||
async def personality(ctx):
|
||||
personality_type = ctx.message.content.split(" ", maxsplit=1)[1]
|
||||
edit_channel_config(ctx.channel.id, "personality", personality_type)
|
||||
await ctx.send("Personality changed to " + personality_type)
|
||||
|
||||
|
||||
'''@bot.command(
|
||||
description="Secret Santa Register",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue