// Loop through arguments to find username and email
for_,arg:=rangeargs[1:]{// Skip the command itself
ifstrings.HasPrefix(arg,"--username="){
username=strings.TrimPrefix(arg,"--username=")
}elseifstrings.HasPrefix(arg,"--email="){
email=strings.TrimPrefix(arg,"--email=")
}
}
// If no username parameter is provided, use the user's Discord nickname or username
ifusername==""{
member,err:=s.GuildMember(m.GuildID,m.Author.ID)
iferr!=nil{
username=m.Author.Username
}elseifmember.Nick!=""{
username=member.Nick
}else{
username=m.Author.Username
}
}
// Remove trailing period from username if present
username=strings.TrimRight(username,".")
// If no email parameter is provided, use the default email format
ifemail==""{
email=fmt.Sprintf("%s@git.beisel.it",username)
}
// Validate the username
isValid,err:=validateUsername(username)
iferr!=nil{
s.ChannelMessageSend(m.ChannelID,"Invalid username. Username must consist of alphanumeric characters, dashes, underscores, and dots. It cannot begin or end with non-alphanumeric characters, and consecutive non-alphanumeric characters are forbidden.")
return
}
if!isValid{
s.ChannelMessageSend(m.ChannelID,"Invalid username. Username must consist of alphanumeric characters, dashes, underscores, and dots. It cannot begin or end with non-alphanumeric characters, and consecutive non-alphanumeric characters are forbidden.")
return
}
fmt.Println("Creating user:",username)
// Auto-generate a password
password,err:=generatePassword(12)// You can choose the length of the password
iferr!=nil{
s.ChannelMessageSend(m.ChannelID,"Failed to generate a secure password.")
return
}
// Create user in Gitea
err=createUserInGitea(username,email,password)
iferr!=nil{
s.ChannelMessageSend(m.ChannelID,"Failed to create user in Gitea.")
return
}
// Send DM with login details and instructions
dmChannel,err:=s.UserChannelCreate(m.Author.ID)
iferr!=nil{
s.ChannelMessageSend(m.ChannelID,"Failed to send DM.")
return
}
dmMessage:=fmt.Sprintf("You can now log in to %s using:\n\nUsername: %s\nPassword: %s\n\nYour E-Mail has temporarily been set to \"%s\". Please make sure to set this to your correct e-mail address and update your password immediately.",giteaURL,username,password,email)