README.md; debloted log.go

This commit is contained in:
Jann Pächnatz 2023-12-04 00:16:28 +01:00
parent f15f804fe8
commit 5c625625b9
4 changed files with 39 additions and 86 deletions

View File

@ -64,9 +64,29 @@ Don't touch the db folder or the included files if you don't know what you are d
### Features
- Chat Moderation
- Polls
- User Bot Prevention
- Twitch / YouTube integration (Notifications)
#### Please note
Already existing features can be removed or may not work in the future. To provide the best experience, please use always the latest version and don't use nightly builds or pre-release builds or any kind of pre-release version for production. There is no warranty for backwards compatibility but if you always update the program, there prpbably won't be any complications.
#### Feature Support Overview
|Symbol |Meaing |
|-------|------------------|
|🔴 |no support at all |
|🟡 |not full support |
|🟢 |full support |
|Feature Name |Feature Description |Feature Support |
|---------------------------------|------------------------------------------------------------|----------------|
|Chat Moderation |Filter swearing, profane language, URLs (or just blocked URLs) and deletes not allowed messages |🔴 |
|Polls |Create polls for other users |🔴 |
|User Verification |Remove annoying bots from your server |🔴 |
|Twitch Integration |Get notifications for a started live streams |🟡 |
|OpenWeatherMap Integration |Get information about the weather forecast |🔴 |
|YouTube Integration |Get notification about a started Live stream or a new video |🔴 |
|BadgerDB Database |Store user-related data and data used by modules |🟡 |
|BadgerDB Database Backups |Use automated or manual created backups to |🔴 |
|Automated Server Security Review |Automated security service which will check your server audit log and watched over the bots |🔴 |
|NSFW Content Guard |Automated service which will check any messages including images, animated images and videos |🔴 |
|ko-fi.com Integration |Give special roles to users who send donations via ko-fi.com |🔴 |

19
bot.go
View File

@ -89,22 +89,11 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
}
switch strings.TrimPrefix(cmd, botPrefix) {
case "uptime":
days := 0
hours := 0
mins := 0
secs := int(time.Since(started).Seconds())
for secs >= 60 {
mins++
secs -= 60
}
for mins >= 60 {
hours++
mins -= 60
}
for hours >= 24 {
days++
secs -= 24
}
mins := secs / 60
hours := mins / 60
days := hours / 24
secs -= mins*60 + (hours * 60 * 60) + (days * 24 * 60 * 60)
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("I'm running for %d days, %d hours, %d minutes and %d seconds.", days, hours, mins, secs))
case "time":
now := time.Now()

76
log.go
View File

@ -28,7 +28,8 @@ func (l *Logger) ResetOutput() {
l.output = nil
}
func (l *Logger) Info(a ...any) {
// cat stands for category (Example categories: "INFO", "WARN", "FATAL")
func (l *Logger) Log(cat string, style *color.Color, a ...any) {
now := time.Now()
day, month, year := now.Day(), now.Month(), now.Year()
hour, min, sec := now.Hour(), now.Minute(), now.Second()
@ -56,80 +57,23 @@ func (l *Logger) Info(a ...any) {
}
s := fmt.Sprint(a...)
style := color.New(color.FgWhite, color.Bold)
data := fmt.Sprintf("[%s.%s.%d - %s:%s:%s] %s - %s\n", dayStr, monthStr, year, hourStr, minStr, secStr, style.Sprint("INFO"), s)
data := fmt.Sprintf("[%s/%s/%d - %s:%s:%s] %s - %s\n", monthStr, dayStr, year, hourStr, minStr, secStr, style.Sprint(cat), s)
for _, out := range l.output {
out.Write([]byte(data))
}
}
func (l *Logger) Info(a ...any) {
style := color.New(color.FgWhite, color.Bold)
l.Log("INFO", style, a...)
}
func (l *Logger) Warn(a ...any) {
now := time.Now()
day, month, year := now.Day(), now.Month(), now.Year()
hour, min, sec := now.Hour(), now.Minute(), now.Second()
dayStr := fmt.Sprint(int(day))
monthStr := fmt.Sprint(int(month))
hourStr := fmt.Sprint(int(hour))
minStr := fmt.Sprint(int(min))
secStr := fmt.Sprint(int(sec))
if len(dayStr) < 2 {
dayStr = "0" + dayStr
}
if len(monthStr) < 2 {
monthStr = "0" + monthStr
}
if len(hourStr) < 2 {
hourStr = "0" + hourStr
}
if len(minStr) < 2 {
minStr = "0" + minStr
}
if len(secStr) < 2 {
secStr = "0" + secStr
}
s := fmt.Sprint(a...)
style := color.New(color.FgYellow, color.Bold)
data := fmt.Sprintf("[%s.%s.%d - %s:%s:%s] %s - %s\n", dayStr, monthStr, year, hourStr, minStr, secStr, style.Sprint("WARN"), s)
for _, out := range l.output {
out.Write([]byte(data))
}
l.Log("WARN", style, a...)
}
func (l *Logger) Fatal(a ...any) {
now := time.Now()
day, month, year := now.Day(), now.Month(), now.Year()
hour, min, sec := now.Hour(), now.Minute(), now.Second()
dayStr := fmt.Sprint(int(day))
monthStr := fmt.Sprint(int(month))
hourStr := fmt.Sprint(int(hour))
minStr := fmt.Sprint(int(min))
secStr := fmt.Sprint(int(sec))
if len(dayStr) < 2 {
dayStr = "0" + dayStr
}
if len(monthStr) < 2 {
monthStr = "0" + monthStr
}
if len(hourStr) < 2 {
hourStr = "0" + hourStr
}
if len(minStr) < 2 {
minStr = "0" + minStr
}
if len(secStr) < 2 {
secStr = "0" + secStr
}
s := fmt.Sprint(a...)
style := color.New(color.FgRed, color.Bold)
data := fmt.Sprintf("[%s.%s.%d - %s:%s:%s] %s - %s\n", dayStr, monthStr, year, hourStr, minStr, secStr, style.Sprint("FATAL"), s)
for _, out := range l.output {
out.Write([]byte(data))
}
os.Exit(-1)
l.Log("FATAL", style, a...)
}

View File

@ -89,7 +89,7 @@ func Twitch_IsLive(user string) (bool, *helix.Stream, string) {
func Twitch_SendNotification(session *discordgo.Session, stream helix.Stream, channelID, profileImage string) {
session.ChannelMessageSendEmbed(channelID, &discordgo.MessageEmbed{
Color: int(0x5c32a8), // #5c32a8
Title: fmt.Sprintf("%s is live on Twitch!", stream.UserName),
Title: fmt.Sprintf("%s is now live on Twitch!", stream.UserName),
Description: stream.Title,
Fields: []*discordgo.MessageEmbedField{
{