forked from gooberinc/goober
created messages.py
This commit is contained in:
parent
bd3065e885
commit
221b8c70a3
2 changed files with 58 additions and 50 deletions
52
bot.py
52
bot.py
|
@ -21,6 +21,7 @@ from modules.central import ping_server
|
|||
from modules.translations import *
|
||||
from modules.markovmemory import *
|
||||
from modules.version import *
|
||||
from modules.messages import *
|
||||
|
||||
print(splashtext) # you can use https://patorjk.com/software/taag/ for 3d text or just remove this entirely
|
||||
check_for_update()
|
||||
|
@ -42,9 +43,7 @@ def check_resources():
|
|||
|
||||
check_resources()
|
||||
|
||||
from nltk.sentiment.vader import SentimentIntensityAnalyzer
|
||||
from nltk.tokenize import word_tokenize
|
||||
analyzer = SentimentIntensityAnalyzer()
|
||||
|
||||
|
||||
def download_json():
|
||||
locales_dir = "locales"
|
||||
|
@ -83,16 +82,6 @@ async def load_cogs_from_folder(bot, folder_name="cogs"):
|
|||
|
||||
currenthash = ""
|
||||
|
||||
#this doesnt work and im extremely pissed and mad
|
||||
def append_mentions_to_18digit_integer(message):
|
||||
pattern = r'\b\d{18}\b'
|
||||
return re.sub(pattern, lambda match: f"", message)
|
||||
|
||||
def preprocess_message(message):
|
||||
message = append_mentions_to_18digit_integer(message)
|
||||
tokens = word_tokenize(message)
|
||||
tokens = [token for token in tokens if token.isalnum()]
|
||||
return " ".join(tokens)
|
||||
|
||||
|
||||
intents = discord.Intents.default()
|
||||
|
@ -143,44 +132,7 @@ async def on_ready():
|
|||
|
||||
positive_gifs = os.getenv("POSITIVE_GIFS").split(',')
|
||||
|
||||
def is_positive(sentence):
|
||||
scores = analyzer.polarity_scores(sentence)
|
||||
sentiment_score = scores['compound']
|
||||
|
||||
# forcin this fucker
|
||||
debug_message = f"{DEBUG}{get_translation(LOCALE, 'sentence_positivity')} {sentiment_score}{RESET}"
|
||||
print(debug_message)
|
||||
|
||||
return sentiment_score > 0.1
|
||||
|
||||
|
||||
async def send_message(ctx, message=None, embed=None, file=None, edit=False, message_reference=None):
|
||||
if edit and message_reference:
|
||||
try:
|
||||
# Editing the existing message
|
||||
await message_reference.edit(content=message, embed=embed)
|
||||
except Exception as e:
|
||||
await ctx.send(f"{RED}{get_translation(LOCALE, 'edit_fail')} {e}{RESET}")
|
||||
else:
|
||||
if hasattr(ctx, "respond"):
|
||||
# For slash command contexts
|
||||
sent_message = None
|
||||
if embed:
|
||||
sent_message = await ctx.respond(embed=embed, ephemeral=False)
|
||||
elif message:
|
||||
sent_message = await ctx.respond(message, ephemeral=False)
|
||||
if file:
|
||||
sent_message = await ctx.respond(file=file, ephemeral=False)
|
||||
else:
|
||||
|
||||
sent_message = None
|
||||
if embed:
|
||||
sent_message = await ctx.send(embed=embed)
|
||||
elif message:
|
||||
sent_message = await ctx.send(message)
|
||||
if file:
|
||||
sent_message = await ctx.send(file=file)
|
||||
return sent_message
|
||||
|
||||
@bot.hybrid_command(description=f"{get_translation(LOCALE, 'command_desc_retrain')}")
|
||||
async def retrain(ctx):
|
||||
|
|
56
modules/messages.py
Normal file
56
modules/messages.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
import re
|
||||
from modules.globalvars import *
|
||||
from modules.translations import *
|
||||
from nltk.sentiment.vader import SentimentIntensityAnalyzer
|
||||
from nltk.tokenize import word_tokenize
|
||||
analyzer = SentimentIntensityAnalyzer()
|
||||
|
||||
def is_positive(sentence):
|
||||
scores = analyzer.polarity_scores(sentence)
|
||||
sentiment_score = scores['compound']
|
||||
|
||||
# forcin this fucker
|
||||
debug_message = f"{DEBUG}{get_translation(LOCALE, 'sentence_positivity')} {sentiment_score}{RESET}"
|
||||
print(debug_message)
|
||||
|
||||
return sentiment_score > 0.1
|
||||
|
||||
|
||||
async def send_message(ctx, message=None, embed=None, file=None, edit=False, message_reference=None):
|
||||
if edit and message_reference:
|
||||
try:
|
||||
# Editing the existing message
|
||||
await message_reference.edit(content=message, embed=embed)
|
||||
except Exception as e:
|
||||
await ctx.send(f"{RED}{get_translation(LOCALE, 'edit_fail')} {e}{RESET}")
|
||||
else:
|
||||
if hasattr(ctx, "respond"):
|
||||
# For slash command contexts
|
||||
sent_message = None
|
||||
if embed:
|
||||
sent_message = await ctx.respond(embed=embed, ephemeral=False)
|
||||
elif message:
|
||||
sent_message = await ctx.respond(message, ephemeral=False)
|
||||
if file:
|
||||
sent_message = await ctx.respond(file=file, ephemeral=False)
|
||||
else:
|
||||
|
||||
sent_message = None
|
||||
if embed:
|
||||
sent_message = await ctx.send(embed=embed)
|
||||
elif message:
|
||||
sent_message = await ctx.send(message)
|
||||
if file:
|
||||
sent_message = await ctx.send(file=file)
|
||||
return sent_message
|
||||
|
||||
#this doesnt work and im extremely pissed and mad
|
||||
def append_mentions_to_18digit_integer(message):
|
||||
pattern = r'\b\d{18}\b'
|
||||
return re.sub(pattern, lambda match: f"", message)
|
||||
|
||||
def preprocess_message(message):
|
||||
message = append_mentions_to_18digit_integer(message)
|
||||
tokens = word_tokenize(message)
|
||||
tokens = [token for token in tokens if token.isalnum()]
|
||||
return " ".join(tokens)
|
Loading…
Add table
Add a link
Reference in a new issue