Updated logging
This commit is contained in:
parent
a190e523d4
commit
f0fc5b643a
10
main.py
10
main.py
|
|
@ -11,23 +11,25 @@ class DankBot(discord.ext.commands.Bot):
|
|||
plugin_files = glob.glob(os.path.join(plugin_path, '**', 'plugin.py'), recursive=True)
|
||||
for plugin_file in plugin_files:
|
||||
plugin_name = os.path.basename(os.path.dirname(plugin_file))
|
||||
print(f"Loading plugin {plugin_name}")
|
||||
logger.info(f"Loading plugin {plugin_name}")
|
||||
await self.load_extension(f'plugins.{plugin_name}.plugin')
|
||||
|
||||
async def on_ready(self):
|
||||
print(f'Logged on as {self.user}!')
|
||||
logger.info(f'Logged on as {self.user}!')
|
||||
await self.load_plugins()
|
||||
await self.change_presence(activity=discord.Game("with the bots"))
|
||||
|
||||
async def on_message(self, message):
|
||||
print(f'Message from {message.author}: {message.content}')
|
||||
logger.info(f'Message from {message.author}: {message.content}')
|
||||
await self.process_commands(message)
|
||||
|
||||
async def main():
|
||||
intents = discord.Intents.default()
|
||||
intents.message_content = True
|
||||
intents.members = True
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
discord.utils.setup_logging(level=logging.INFO, root=True)
|
||||
global logger
|
||||
logger = logging.getLogger("bot.main")
|
||||
|
||||
with open(".token") as token_file:
|
||||
token = token_file.read()
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@ import aiohttp
|
|||
import yaml
|
||||
import random
|
||||
import os
|
||||
import logging
|
||||
|
||||
logger=logging.getLogger("plugin.botchat")
|
||||
plugin_folder=os.path.dirname(os.path.realpath(__file__))
|
||||
prompts_folder=os.path.join(plugin_folder, 'prompts')
|
||||
default_prompt="default.txt"
|
||||
|
|
@ -20,24 +22,24 @@ async def prompt_llm(prompt):
|
|||
:param prompt: prompt to complete
|
||||
:return: returns a string consisting of completion text
|
||||
"""
|
||||
print("Prompting LLM")
|
||||
print(f"PROMPT DATA\n{prompt}")
|
||||
logger.info("Prompting LLM")
|
||||
logger.info(f"PROMPT DATA\n{prompt}")
|
||||
async with aiohttp.ClientSession(llm_data["api_base"]) as session:
|
||||
async with session.post("/completion", json={"prompt": prompt, "n_predict": 250, "mirostat": 2}) as resp:
|
||||
print(f"LLM response status {resp.status}")
|
||||
async with session.post("/completion", json={"prompt": prompt, "n_predict": 350, "mirostat": 2}) as resp:
|
||||
logger.info(f"LLM response status {resp.status}")
|
||||
response_json=await resp.json()
|
||||
content=response_json["content"]
|
||||
return content
|
||||
|
||||
def get_message_contents(msg):
|
||||
"""
|
||||
Given a Discord message object, prints the contents in an IRC-like format
|
||||
Given a Discord message object, logger.infos the contents in an IRC-like format
|
||||
|
||||
:param msg: discord.Message to get the contents of
|
||||
:return: returns a string in the format "user: message"
|
||||
"""
|
||||
message_text = f"{msg.author.name}: {msg.clean_content}"
|
||||
print(f"Message contents -- {message_text}")
|
||||
logger.info(f"Message contents -- {message_text}")
|
||||
return message_text
|
||||
|
||||
async def get_chat_history(ctx, limit=20):
|
||||
|
|
@ -98,7 +100,7 @@ async def send_chat_responses(ctx, response_text):
|
|||
:param ctx: Message context that we're replying to
|
||||
:param response_text: String containing message we want to send
|
||||
"""
|
||||
print("Processing chat response")
|
||||
logger.info("Processing chat response")
|
||||
fullResponseLog = "dank-bot:" + response_text # first response won't include the user
|
||||
responseLines = fullResponseLog.splitlines()
|
||||
output_strs = []
|
||||
|
|
@ -147,28 +149,28 @@ async def handle_message(ctx):
|
|||
|
||||
:param ctx: Message context
|
||||
"""
|
||||
print("Dank-bot received message")
|
||||
print(f"Dank-bot ID is {llm_data['bot'].user.id}")
|
||||
logger.info("Dank-bot received message")
|
||||
logger.info(f"Dank-bot ID is {llm_data['bot'].user.id}")
|
||||
bot_id = llm_data['bot'].user.id
|
||||
|
||||
# First case, bot DMed
|
||||
if (isinstance(ctx.channel,discord.DMChannel) and ctx.author.id != bot_id):
|
||||
print("Dank-bot DMed, responding")
|
||||
logger.info("Dank-bot DMed, responding")
|
||||
await llm_response(ctx)
|
||||
return
|
||||
|
||||
# Second case, bot mentioned
|
||||
bot_mentions=list(filter(lambda x: x.id == bot_id, ctx.mentions))
|
||||
if (len(bot_mentions) > 0):
|
||||
print("Dank-bot mentioned, responding")
|
||||
logger.info("Dank-bot mentioned, responding")
|
||||
await llm_response(ctx)
|
||||
return
|
||||
|
||||
# Other case, random response
|
||||
random_roll = random.random()
|
||||
print(f"Dank-bot rolled {random_roll}")
|
||||
logger.info(f"Dank-bot rolled {random_roll}")
|
||||
if (random_roll < llm_data['response_probability']):
|
||||
print(f"{random_roll} < {llm_data['response_probability']}, responding")
|
||||
logger.info(f"{random_roll} < {llm_data['response_probability']}, responding")
|
||||
await llm_response(ctx)
|
||||
return
|
||||
|
||||
|
|
@ -185,4 +187,4 @@ async def setup(bot):
|
|||
bot.add_command(llm_response)
|
||||
bot.add_listener(handle_message, "on_message")
|
||||
llm_data["bot"] = bot
|
||||
print("LLM interface initialized")
|
||||
logger.info("LLM interface initialized")
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
# Posts a dank pepe in the chat
|
||||
from discord.ext import commands
|
||||
import discord
|
||||
import logging
|
||||
import random
|
||||
import os
|
||||
|
||||
logger=logging.getLogger("plugin.pepe")
|
||||
plugin_folder=os.path.dirname(os.path.realpath(__file__))
|
||||
pepe_filename=os.path.join(plugin_folder, 'pepes.txt')
|
||||
|
||||
|
|
@ -16,5 +18,5 @@ async def send_pepe(ctx):
|
|||
await ctx.send(f'{chosen_pepe}')
|
||||
|
||||
async def setup(bot):
|
||||
print("Rare Pepes initialized")
|
||||
logger.info("Rare Pepes initialized")
|
||||
bot.add_command(send_pepe)
|
||||
|
|
|
|||
Loading…
Reference in New Issue