Added password generator & added onefetch support

This commit is contained in:
Minecodes 2023-07-10 18:07:35 +02:00
parent d193db7a31
commit 075c0cac69
Signed by: thies
GPG key ID: E6CD3105E59C12D1
4 changed files with 65 additions and 4 deletions

View file

@ -17,6 +17,7 @@ Invite: [discord.com/api/oauth2/authorize?client_id=987391496724570134&permissio
| httpcat | Get a HTTP status code as a cat picture |
| fox | Get a random fox picture |
| qrcode | Generate a QR code |
| password | Generate a random password |
| trains | Trainboy: me gusta los trenes |

BIN
assets/Tatake.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

57
main.go
View file

@ -8,6 +8,7 @@ import (
"fmt"
"math/rand"
"strconv"
"strings"
"time"
//"fmt"
@ -25,10 +26,13 @@ import (
)
var (
GuildID = flag.String("guild", "", "Test guild ID. If not passed - bot registers commands globally")
BotToken = flag.String("token", "", "Bot access token")
RemoveCommands = flag.Bool("rmcmd", true, "Remove all commands after shutdowning or not")
InfoMessages = []string{
GuildID = flag.String("guild", "", "Test guild ID. If not passed - bot registers commands globally")
BotToken = flag.String("token", "", "Bot access token")
RemoveCommands = flag.Bool("rmcmd", true, "Remove all commands after shutdowning or not")
minPasswordLength = float64(12)
maxPasswordLength = float64(100)
passwordChars = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_+{}[]:;?/.,<>")
InfoMessages = []string{
`Hello, I'm a bot made by <@!556848982433857537>!`,
`Hello SlimeDiamond`,
`"Never trust a tech guy with a rat tail—too easy to carve secrets out of him." - Lone Star (Mr. Robot)`,
@ -64,6 +68,19 @@ func init() {
}
}
func gen(length int64) string {
password := make([]rune, length)
for i := range password {
password[i] = passwordChars[rand.Intn(len(passwordChars))]
}
// check if password has at least one number, one uppercase letter, one lowercase letter and one special character
// if not, generate a new password
if !strings.ContainsAny(string(password), "0123456789") || !strings.ContainsAny(string(password), "abcdefghijklmnopqrstuvwxyz") || !strings.ContainsAny(string(password), "ABCDEFGHIJKLMNOPQRSTUVWXYZ") || !strings.ContainsAny(string(password), "!@#$%^&*()_+{}[]:;?/.,<>") {
return gen(length)
}
return string(password)
}
var (
integerOptionMinValue = 1.0
dmPermission = false
@ -159,6 +176,20 @@ var (
},
},
},
{
Name: "password",
Description: "Generate a random password",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionInteger,
Name: "length",
Description: "Length of the password",
Required: true,
MinValue: &minPasswordLength,
MaxValue: maxPasswordLength,
},
},
},
}
commandHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate){
@ -521,6 +552,24 @@ var (
},
})
},
"password": func(s *discordgo.Session, i *discordgo.InteractionCreate) {
length := i.Interaction.ApplicationCommandData().Options[0].IntValue()
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "",
Flags: discordgo.MessageFlagsEphemeral,
Embeds: []*discordgo.MessageEmbed{
{
Title: "Password",
Color: 0x00ff00,
Description: "Your password is: `" + gen(length) + "`",
},
},
},
})
},
}
)

11
onefetch.sh Executable file
View file

@ -0,0 +1,11 @@
#!/usr/bin/bash
if [[ "$TERM" == "xterm-kitty" ]]; then
onefetch --image assets/Tatake.png --image-protocol kitty
elif [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
onefetch --image assets/Tatake.png --image-protocol iterm
elif [[ "$TERM" == *sixel* ]]; then
onefetch --image assets/Tatake.png --image-protocol sixel
else
onefetch
fi