Exemple #1
0
        private DateTime ConvertDT(string _d, int i)
        {
            KLog.Debug($"{i}");  // LOOK AT THIS, i Might be useless

            string[] dt = _d.Split(' ');

            string[] date = dt[0].Split('/');
            string[] time = dt[1].Split(':');

            int d, m, y, h, mi, s;

            // Date
            int.TryParse(date[0], out m);
            int.TryParse(date[1], out d);
            int.TryParse(date[2], out y);

            int.TryParse(time[0], out h);
            int.TryParse(time[1], out mi);
            int.TryParse(time[2], out s);

            h %= 12;  // Convert to 24 hour format part 1

            if (dt[2] == "PM")
            {
                h += 12;
            }

            DateTime ddd = new DateTime(y, m, d, h, mi, s);

            return(ddd);
        }
Exemple #2
0
        /// <summary>
        /// Counts the number of items (or the number of a specific item) in the inventory.
        /// </summary>
        /// <param name="item">The ID of the item to get the count of</param>
        /// <returns>The count of the specified item, or the total number of items if no item is specified</returns>
        public int ItemCount(uint?item = null)
        {
            // check if an item was specified
            if (item == null)
            {
                // if it wasn't, get the total count of all items
                int  t       = 0;     // variable to store item total
                bool cleanup = false; // bool for cleanup so if it

                foreach (uint k in Items.Keys)
                {
                    int i = Items[k];

                    // check to make sure the items don't have bizarre counts
                    if (i <= 0)
                    {
                        KLog.Debug($"[UIN] Item [{k}] had count {i}, and was removed.");
                        cleanup = true; // if so, make sure to clean up the inventory at the end of the method
                        continue;       // and skip the item
                    }

                    t += i;  // add it to the total
                }

                if (cleanup)
                {
                    // if the inventory needs cleaning, do so.
                    ParseInventory();
                }

                return(t);  // return the total
            }
            else
            {
                // The item was specified, so count it
                uint i = item.Value;

                if (!Items.ContainsKey(i))
                {
                    // error checks
                    return(0);
                }

                if (Items[i] <= 0)
                {
                    // Fix broken inventories
                    ParseInventory();
                    return(0);
                }

                return(Items[i]);
            }
        }
        /// <summary>
        /// Happens whenever anything about a user (except roles) updates
        /// </summary>
        /// <remarks>
        /// This is pretty dumb. 
        /// It's up to you to figure out what changed. It could be anything from a new pfp or username,
        /// to changing your status from idle to online.
        /// </remarks>
        /// <param name="before">User before</param>
        /// <param name="after">User after</param>
        /// <returns></returns>
        public async Task OnMemberUpdate(SocketGuildUser before, SocketGuildUser after) {
            if (before.Guild != ServerData.Server || before.Status != after.Status) return; // If it's not on kamtro, or it was just a status update (online to AFK, etc), ignore it

            KLog.Debug($"Member {BotUtils.GetFullUsername(before)} updated.");

            if(BotUtils.GetFullUsername(before) != BotUtils.GetFullUsername(after)) {
                // If the user changed their name.
                KLog.Debug($"Username Change: {BotUtils.GetFullUsername(before)} --> {BotUtils.GetFullUsername(after)}");
                
                NameChangeEmbed nce = new NameChangeEmbed(before, after);
                await nce.Display(ServerData.LogChannel, after.Username + "#" + after.Discriminator);
            }

            KLog.Debug("FLAG GH-A");

            if (before.Nickname != after.Nickname) {
                // If the nickame changed
                KLog.Debug($"Nickname Change: {BotUtils.GetFullUsername(before)}: {(before.Nickname == null ? "[No Nickname]":$"'{before.Nickname}'")} --> {(after.Nickname == null ? "[No Nickname]" : $"'{after.Nickname}'")}");

                NameChangeEmbed nce = new NameChangeEmbed(before, after, true);
                await nce.Display(ServerData.LogChannel, after.Username + "#" + after.Discriminator);
            }
Exemple #4
0
        public async Task RemoveRoleAsync([Remainder] string message = "")
        {
            SocketGuildUser user = BotUtils.GetGUser(Context);

            KLog.Debug($"RM - Modifiable Roles: {(ServerData.ModifiableRoles == null ? "NULL" : ServerData.ModifiableRoles.ToString())}");
            KLog.Debug($"RM - All Roles: {(ServerData.AllRoles == null ? "NULL" : ServerData.AllRoles.ToString())}");
            KLog.Debug($"RM - User: {user}");

            // Find if user entered a role
            if (string.IsNullOrWhiteSpace(message))
            {
                SocketGuildUser _user = BotUtils.GetGUser(Context);
                RoleEmbed       embed = new RoleEmbed(Context, _user);

                await embed.Display(Context.Channel);

                ulong id = Context.Message.Author.Id;
                if (EventQueueManager.EventQueue.ContainsKey(id))
                {
                    // If the user is in the queue
                    EventQueueManager.EventQueue[id].Add(new EventQueueNode(embed));  // Add the action to their list
                }
                else
                {
                    // otherwise
                    EventQueueManager.EventQueue.Add(id, new List <EventQueueNode>()); // Create the list
                    EventQueueManager.EventQueue[id].Add(new EventQueueNode(embed));   // And add the action to their list
                }
            }
            else
            {
                // Check all roles - Arcy
                foreach (SocketRole role in ServerData.AllRoles)
                {
                    // Find if the message matches the role closely enough - Arcy
                    if (UtilStringComparison.CompareWordScore(message, role.Name) >= 0.66)
                    {
                        // ALREADY DOESN'T HAVE ROLE
                        // Check if user already doesn't have the role - Arcy
                        if (!user.HasRole(role))
                        {
                            // First person response if DMs - Arcy
                            if (Context.Channel is IDMChannel)
                            {
                                await ReplyAsync(BotUtils.KamtroText($"You already do not have the {CultureInfo.CurrentCulture.TextInfo.ToTitleCase(role.Name.ToLower())} role."));

                                return;
                            }
                            // Third person response elsewhere - Arcy
                            else
                            {
                                // Reply using nickname - Arcy
                                if (user.Nickname != null)
                                {
                                    await ReplyAsync(BotUtils.KamtroText($"{user.Nickname} already does not have the {CultureInfo.CurrentCulture.TextInfo.ToTitleCase(role.Name.ToLower())} role."));

                                    return;
                                }
                                // Reply using username - Arcy
                                else
                                {
                                    await ReplyAsync(BotUtils.KamtroText($"{user.Username} already does not have the {CultureInfo.CurrentCulture.TextInfo.ToTitleCase(role.Name.ToLower())} role."));

                                    return;
                                }
                            }
                        }

                        /// REMOVING ROLE
                        // Check if it is a modifiable role - Arcy
                        else if (ServerData.ModifiableRoles.Contains(role))
                        {
                            // Catch instance that the role is higher in heirarchy than bot role - Arcy
                            KLog.Debug($"ROLE: {(role == null ? "NULL" : role.ToString())}");
                            KLog.Debug($"BOT ROLE: {(ServerData.KamtroBotRole == null ? "NULL" : ServerData.KamtroBotRole.ToString())}");
                            if (role.Position >= ServerData.KamtroBotRole.Position)
                            {
                                await ReplyAsync(BotUtils.KamtroText($"Uh oh! I cannot manage that role! Please contact Arcy or Carbon and let them know about this!"));

                                break;
                            }
                            else
                            {
                                // Remove the role! Woohoo! - Arcy
                                await user.RemoveRoleAsync(role);

                                // First person response if DMs - Arcy
                                if (Context.Channel is IDMChannel)
                                {
                                    await ReplyAsync(BotUtils.KamtroText($"You no longer have the {CultureInfo.CurrentCulture.TextInfo.ToTitleCase(role.Name.ToLower())} role."));

                                    return;
                                }
                                // Third person response elsewhere - Arcy
                                else
                                {
                                    // Reply using nickname - Arcy
                                    if (user.Nickname != null)
                                    {
                                        await ReplyAsync(BotUtils.KamtroText($"{user.Nickname} no longer has the {CultureInfo.CurrentCulture.TextInfo.ToTitleCase(role.Name.ToLower())} role."));

                                        return;
                                    }
                                    // Reply using username - Arcy
                                    else
                                    {
                                        await ReplyAsync(BotUtils.KamtroText($"{user.Username} no longer has the {CultureInfo.CurrentCulture.TextInfo.ToTitleCase(role.Name.ToLower())} role."));

                                        return;
                                    }
                                }
                            }
                        }

                        /// NOT MODIFIABLE
                        // Not modifiable. Respond with the role not being able to be added/removed - Arcy
                        else
                        {
                            // Extra flavor for removing mod roles - Arcy
                            if (ServerData.ModeratorRoles.Contains(role))
                            {
                                // First person response if DMs - Arcy
                                if (Context.Channel is IDMChannel)
                                {
                                    await ReplyAsync(BotUtils.KamtroText($"Just ask Kamex or Retro."));

                                    return;
                                }
                                // Third person response elsewhere - Arcy
                                else
                                {
                                    // Reply using nickname - Arcy
                                    if (user.Nickname != null)
                                    {
                                        await ReplyAsync(BotUtils.KamtroText($"Just ask Kamex or Retro, {user.Nickname}."));

                                        return;
                                    }
                                    // Reply using username - Arcy
                                    else
                                    {
                                        await ReplyAsync(BotUtils.KamtroText($"Just ask Kamex or Retro, {user.Username}."));

                                        return;
                                    }
                                }
                            }
                            else
                            {
                                await ReplyAsync(BotUtils.KamtroText($"The {CultureInfo.CurrentCulture.TextInfo.ToTitleCase(role.Name.ToLower())} role cannot be removed."));

                                return;
                            }
                        }
                    }
                }

                /// ROLE CANNOT BE FOUND
                await ReplyAsync(BotUtils.KamtroText($"I do not recognize that role. Please make sure you are spelling the role correctly. (Copy-Paste should always work!)"));
            }
        }