Example #1
0
//Welcome sends an acknowledge to the terminal that it is listening, and prints the current Username
func Welcome(dg *discordgo.Session) {
	d := color.New(color.FgYellow, color.Bold)
	d.Printf("Listening!\n\n")

	user, _ := dg.User("@me")
	d.Printf("Welcome, %s!\n\n", user.Username)
}
Example #2
0
func fetchUser(sess *discordgo.Session, userid string) *discordgo.User {
	var result *discordgo.User
	retryOnBadGateway(func() error {
		var err error
		result, err = sess.User(userid)
		if err != nil {
			return err
		}
		return nil
	})
	return result
}
Example #3
0
func manualUnban(s *discordgo.Session, channelID string,
	roleID []string, arr []string) {

	if checkForPermissions(s, channelID, roleID) &&
		len(arr) == 3 && len(arr[2]) == 21 {
		arr[2] = arr[2][2 : len(arr[2])-1]
		pgDb := dbConn()
		tx, err := pgDb.Begin()
		checkErr(err)

		user, _ := s.User(arr[2])
		name := user.Username

		rows, err := tx.Query(
			"SELECT id, guild_id, role_id FROM bans WHERE name = $1", name)
		checkErr(err)

		flag := false
		for rows.Next() {
			flag = true
			var id, guild_id, role_id string
			rows.Scan(&id, &guild_id, &role_id)

			if len(guild_id) != 0 {
				rows.Close()
				_, err = tx.Exec("DELETE FROM bans WHERE id = $1", id)
				checkErr(err)
				s.GuildMemberEdit(guild_id, arr[2], []string{role_id})
				s.ChannelMessageSend(channelID,
					fmt.Sprintf("User %s has been unbanned", name))
				break
			}
		}
		tx.Commit()
		pgDb.Close()
		if flag == false {
			s.ChannelMessageSend(channelID,
				fmt.Sprintf("User %s is not banned", name))
		}

	} else {
		s.ChannelMessageSend(channelID,
			fmt.Sprintf("Please check the parameters"))
	}
}