Compare commits

..
9 Commits
Author SHA1 Message Date
Dustin Pianalto 02b5842107 Add milliseconds to timestamp
CI / build (push) Has been cancelled
2021-07-23 12:54:23 -08:00
Dustin Pianalto d345044b3a Add milliseconds to timestamp
CI / build (push) Has been cancelled
2021-07-23 12:39:35 -08:00
Dustin Pianalto b3aff0828c Add snowflake command
CI / build (push) Has been cancelled
2021-07-23 12:34:09 -08:00
Dustin Pianalto 3d4518f961 Don't log message edits if the After is blank (problem with message embeds)
CI / build (push) Has been cancelled
2021-07-01 19:54:12 -08:00
Dustin Pianalto 37e8fa52af Fix bug in getting tasks
CI / build (push) Has been cancelled
2021-06-22 12:58:42 -08:00
Dustin Pianalto a370c76ba4 Add Auto Role Feature
CI / build (push) Has been cancelled
2021-06-22 02:20:08 -08:00
Dustin Pianalto 2fe9de279d Add Auto Role Feature
CI / build (push) Has been cancelled
2021-06-22 02:15:42 -08:00
Dustin Pianalto 33776b1129 Add Auto Role Feature
CI / build (push) Has been cancelled
2021-06-22 02:02:47 -08:00
Dustin Pianalto 733cd87896 Add Auto Role Feature
CI / build (push) Has been cancelled
2021-06-22 01:58:31 -08:00
10 changed files with 45 additions and 5 deletions
+2
View File
@@ -83,7 +83,9 @@ func main() {
dg.AddHandler(guild_management.OnMessageUpdate)
dg.AddHandler(guild_management.OnMessageDelete)
dg.AddHandler(user_management.OnGuildMemberAddLogging)
dg.AddHandler(user_management.OnGuildMemberAdd)
dg.AddHandler(user_management.OnGuildMemberRemoveLogging)
dg.AddHandler(user_management.OnGuildMemberRemove)
err = dg.Open()
if err != nil {
+1 -1
View File
@@ -32,7 +32,7 @@ func ParseDateString(inTime time.Time) string {
} else {
dateString = "Now"
}
stamp := inTime.Format("2006-01-02 15:04:05")
stamp := inTime.Format("2006-01-02 15:04:05.000")
return fmt.Sprintf("%v\n%v", dateString, stamp)
}
+4 -1
View File
@@ -19,7 +19,10 @@ func ParseSnowflake(s int64) Snowflake {
PROCESS_ID_MASK = 0x1F000
INCREMENT_MASK = 0xFFF
)
creationTime := time.Unix(((s>>TIME_BITS_LOC)+DISCORD_EPOCH)/1000.0, 0)
t := (s >> TIME_BITS_LOC) + DISCORD_EPOCH
sec := t / 1000.0
nano := t % 1000.0 * 1000000.0
creationTime := time.Unix(sec, nano)
workerID := (s & WORKER_ID_MASK) >> WORKER_ID_LOC
processID := (s & PROCESS_ID_MASK) >> PROCESS_ID_LOC
increment := s & INCREMENT_MASK
@@ -29,6 +29,9 @@ func OnMessageUpdate(session *discordgo.Session, m *discordgo.MessageUpdate) {
log.Println(err)
return
}
if m.Content == "" {
return
}
embed := &discordgo.MessageEmbed{
Title: fmt.Sprintf("Message Edited: %v", msg.ID),
Description: fmt.Sprintf("**Before:** %v\n**After:** %v\nIn Channel: %v", msg.Content, m.Content, channel.Mention()),
+1
View File
@@ -27,6 +27,7 @@ func AddCommandHandlers(h *disgoman.CommandManager) {
_ = h.AddCommand(utils.GitCommand)
_ = h.AddCommand(utils.InviteCommand)
_ = h.AddCommand(utils.PingCommand)
_ = h.AddCommand(utils.SnowflakeCommand)
_ = h.AddCommand(tasks.AddReminderCommand)
_ = h.AddCommand(tags.AddTagCommand)
_ = h.AddCommand(tags.TagCommand)
+2 -2
View File
@@ -325,7 +325,7 @@ func makeAutoRoleCommandFunc(ctx disgoman.Context, args []string) {
return
}
}
_, _ = ctx.Send(fmt.Sprintf("%s will be added to all new memebers.", r.Name))
}
var RemoveAutoRoleCommand = &disgoman.Command{
@@ -385,5 +385,5 @@ func removeAutoRoleCommandFunc(ctx disgoman.Context, args []string) {
return
}
}
_, _ = ctx.Send(fmt.Sprintf("%s will no longer be added to all new memebers.", r.Name))
}
+1
View File
@@ -100,6 +100,7 @@ func getTasksToRun() []Task {
res, err := postgres.DB.Query(query, time.Now())
if err != nil {
log.Println(err)
return nil
}
var tasks []Task
for res.Next() {
@@ -45,6 +45,7 @@ func OnGuildMemberAdd(s *discordgo.Session, member *discordgo.GuildMemberAdd) {
if err != nil {
log.Println("Error getting Auto Join Roles: ", err)
}
log.Println(roles)
for _, r := range roles {
role, err := s.State.Role(member.GuildID, r.ID)
if err != nil {
+29
View File
@@ -218,3 +218,32 @@ func userCommandFunc(ctx disgoman.Context, args []string) {
}
}
}
var SnowflakeCommand = &disgoman.Command{
Name: "s",
Aliases: nil,
Description: "Return the parts of a snowflake",
OwnerOnly: false,
Hidden: false,
RequiredPermissions: 0,
SanitizeEveryone: true,
Invoke: snowflakeCommandFunc,
}
func snowflakeCommandFunc(ctx disgoman.Context, args []string) {
int64ID, err := strconv.ParseInt(args[0], 10, 64)
if err != nil {
ctx.CommandManager.ErrorChannel <- disgoman.CommandError{
Context: ctx,
Message: "Not a valid ID",
Error: err,
}
return
}
s := discord_utils.ParseSnowflake(int64ID)
embed := &discordgo.MessageEmbed{
Title: args[0],
Description: fmt.Sprintf("Created: %s\nWorker: %d\nProcess: %d\nCounter: %d", discord_utils.ParseDateString(s.CreationTime), s.WorkerID, s.ProcessID, s.Increment),
}
_, _ = ctx.Session.ChannelMessageSendEmbed(ctx.Channel.ID, embed)
}
+1 -1
View File
@@ -63,7 +63,7 @@ func (s *RoleService) RemoveAutoRole(r *goff.Role) error {
func (s *RoleService) GetAutoRoles(gID string) ([]*goff.Role, error) {
var roles []*goff.Role
queryString := `SELECT id FROM roles WHERE guild_id = $1`
queryString := `SELECT id FROM roles WHERE guild_id = $1 AND auto_role = true`
rows, err := s.DB.Query(queryString, gID)
if err != nil {
return nil, err