Exemple #1
0
 public async Task AddOwner(ulong id)
 {
     string sql = $"INSERT INTO BotOwners (OwnerID) VALUES ({id})";
     var l = Constants._BOTOWNERS_.ToList();
     l.Add(id);
     Constants._BOTOWNERS_ = l.ToArray();
     DBControl.UpdateDB(sql);
     var m = await Context.Channel.SendMessageAsync($"User {CustomUserTypereader.GetUserFromID(id, Context.Client.Guilds).Result.Username} added as one of my Owners.");
     GlobalVars.AddRandomTracker(m, 5);
 }
Exemple #2
0
        public async Task AddFriend(ulong friendID)
        {
            var user = await CustomUserTypereader.GetUserFromID(friendID, Context.Client.Guilds);
            if (user != null)
            {
                GlobalVars.FriendUsers.Add(friendID, user);

                string sql = $"INSERT INTO Friends (UserID, DateAdded) VALUES ({friendID},'{DateTime.Now.Day}-{DateTime.Now.Month}-{DateTime.Now.Year}')";
                DBControl.UpdateDB(sql);

                await Context.Channel.SendMessageAsync($"Added user {user.Mention} as a friend.\nThey will no longer be timed out and will have more privileges in the future.");
            }
            else
            {
                var msg = await Context.Channel.SendMessageAsync($"User not found (ID: {friendID}");
                GlobalVars.AddRandomTracker(msg, 5);
            }
        }
Exemple #3
0
        public async Task AddIgnore(ulong idiotID)
        {
            var user = await CustomUserTypereader.GetUserFromID(idiotID, Context.Client.Guilds);
            if (user != null)
            {
                GlobalVars.IgnoredUsers.Add(idiotID, user);

                string sql = $"INSERT INTO Ignores (UserID, DateAdded) VALUES ({idiotID},'{DateTime.Now.Day}-{DateTime.Now.Month}-{DateTime.Now.Year}')";
                DBControl.UpdateDB(sql);

                await Context.Channel.SendMessageAsync($"Added user {user.Mention} to the ignore list.\nThey will now be ignored by me.");
            }
            else
            {
                var msg = await Context.Channel.SendMessageAsync($"User not found (ID: {idiotID})");
                GlobalVars.AddRandomTracker(msg, 5);
            }
        }
Exemple #4
0
        public async Task RemindUser(string time, params string[] msg)
        {
            IUser        user          = null;
            List <IUser> userList      = new List <IUser>();
            string       mentionString = "";

            userList.AddRange(Context.Guild.Users);
            userList = userList.GroupBy(o => o.Id).Select(o => o.First()).ToList();
            bool hasMention = false;

            foreach (string s in msg)
            {
                try { user = await CustomUserTypereader.GetUserFromString(s, Context.Guild); mentionString = s; hasMention = true; }
                catch
                {
                    //No Mention found
                }
            }

            time = time.ToLower();
            if (Regex.Match(time, @"^\d+[dhms]$").Success)
            {
                int    i          = time.Contains('d') ? time.IndexOf('d') : (time.Contains('h') ? time.IndexOf('h') : (time.Contains('m') ? time.IndexOf('m') : time.IndexOf('s')));
                string code       = "";
                ulong  multiplier = 1;
                switch (time.Substring(i, 1))
                {
                case "d":
                    code = "days"; multiplier = 24 * 60 * 60; break;

                case "h":
                    code = "hours"; multiplier = 60 * 60; break;

                case "m":
                    code = "minutes"; multiplier = 60; break;

                default:
                    code = "seconds"; break;
                }
                ulong t = ulong.Parse(time.Substring(0, i)) * multiplier;
                if (t > (7 * 24 * 60 * 60))
                {
                    await Context.Channel.SendMessageAsync($"Timespan too large, max amount of time: 7 days *({7 * 24} hours/{7 * 24 * 60} minutes/{7 * 24 * 60 * 60}seconds)*"); return;
                }
                if (msg[0] != "")
                {
                    string fullMessage = string.Join(' ', msg);
                    if (fullMessage.Length > 100)
                    {
                        await Context.Channel.SendMessageAsync($"{Context.User.Mention}, your message is too long, max character limit: 100"); return;
                    }
                    else
                    {
                        if (hasMention)
                        {
                            fullMessage.Replace(mentionString, user.Username);
                        }
                        await Context.Channel.SendMessageAsync($"{Context.User.Mention}, In {(t / multiplier).ToString()} {code} I will remind you of your message. `{fullMessage}`");

                        TimerStart(t * 1000, Context.Channel, Context.User, fullMessage);

                        DateTime triggerAt = DateTime.Now.AddSeconds(t);

                        string sql = $"INSERT INTO Timers (UserID, GuildID, ChannelID, TimerType, TriggerTime, TimerMessage) VALUES (";
                        sql += $"{Context.User.Id}, ";
                        sql += $"{Context.Guild.Id}, ";
                        sql += $"{Context.Channel.Id}, 'remind', ";
                        sql += $"'{triggerAt.Year}-{triggerAt.Month}-{triggerAt.Day}-{triggerAt.Hour}-{triggerAt.Minute}-{triggerAt.Second}-{triggerAt.Millisecond}', ";
                        sql += $"'{Sanitize(fullMessage)}')";

                        DBControl.UpdateDB(sql);
                    }
                }
                else
                {
                    await Context.Channel.SendMessageAsync($"{Context.User.Mention}, You forgot to add a message!");
                }
            }
            else
            {
                await Context.Channel.SendMessageAsync($"Invalid time format");
            }
        }