fancy printing

This commit is contained in:
2025-02-06 18:48:50 +01:00
parent 37950cfece
commit db1b94119a
6 changed files with 85 additions and 12 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
use crate::{Data, Error};
use crate::{Data, Error, rs_println};
use poise::serenity_prelude::{self as serenity, ActivityData};
@@ -13,7 +13,7 @@ pub fn event_handler<'a>(
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> {
Box::pin(async move {
if let serenity::FullEvent::Ready { data_about_bot } = event {
println!(
rs_println!(
"Bot started as user \"{}\" with id {}",
data_about_bot.user.name,
data_about_bot.user.id
+24
View File
@@ -0,0 +1,24 @@
#[macro_export]
macro_rules! rs_println {
($($arg:tt)*) => {
println!("{}RS{} - {}",
"\x1b[31m",
"\x1b[0m",
format!($($arg)*)
);
};
}
#[macro_export]
macro_rules! rs_errln {
($($arg:tt)*) => {
println!("{}ERROR{} RS{} - {}",
"\x1b[41m",
"\x1b[0m\x1b[31m",
"\x1b[0m",
format!($($arg)*)
);
process::exit(-1);
};
}
+1 -7
View File
@@ -4,6 +4,7 @@ mod events;
mod messages;
mod python;
mod reddit_data;
mod macros;
use std::env;
use std::process;
@@ -25,13 +26,6 @@ struct Data {
type Error = Box<dyn std::error::Error + Send + Sync>;
type Context<'a> = poise::Context<'a, Data, Error>;
#[macro_export]
macro_rules! rs_println {
($($arg:tt)*) => {
println!("RS - {}", format!($($arg)*));
};
}
#[tokio::main]
async fn main() {
+8 -2
View File
@@ -2,10 +2,16 @@ from io import TextIOWrapper
from praw import models
import praw
import os
from macros import *
class Bot:
password: str = os.environ["ASSISTANT_R_PASS"]
secret: str = os.environ["ASSISTANT_R_TOKEN"]
password: str = os.environ.get("ASSISTANT_R_PASS")
secret: str = os.environ.get("ASSISTANT_R_TOKEN")
if password is None:
py_error("Environment variable \"ASSISTANT_R_PASS\" is null!")
if secret is None:
py_error("Environment variable \"ASSISTANT_R_TOKEN\" is null!")
r: praw.Reddit = praw.Reddit(
client_id = "iCSRWS6PMlTLwmylCJRYmA",
+16 -1
View File
@@ -1,2 +1,17 @@
from printColors import PrintColors
def py_print(*args: str):
print("Py -", " ".join(args))
print(
PrintColors.FG.blue + "Py" + PrintColors.Special.reset,
"-",
" ".join(args)
)
def py_error(*args: str):
print(
PrintColors.BG.red + "ERROR" + PrintColors.Special.reset,
PrintColors.FG.blue + "Py" + PrintColors.Special.reset,
"-",
" ".join(args)
)
quit()
+34
View File
@@ -0,0 +1,34 @@
class PrintColors:
class Special:
reset = "\033[0m"
bold = "\033[01m"
disable = "\033[02m"
underline = "\033[04m"
reverse = "\033[07m"
strikethrough = "\033[09m"
invisible = "\033[08m"
class FG:
black = "\033[30m"
red = "\033[31m"
green = "\033[32m"
orange = "\033[33m"
blue = "\033[34m"
purple = "\033[35m"
cyan = "\033[36m"
lightgrey = "\033[37m"
darkgrey = "\033[90m"
lightred = "\033[91m"
lightgreen = "\033[92m"
yellow = "\033[93m"
lightblue = "\033[94m"
pink = "\033[95m"
lightcyan = "\033[96m"
class BG:
black = "\033[40m"
red = "\033[41m"
green = "\033[42m"
orange = "\033[43m"
blue = "\033[44m"
purple = "\033[45m"
cyan = "\033[46m"
lightgrey = "\033[47m"