private async Task Client_MessageUpdated(Cacheable <IMessage, ulong> arg1, SocketMessage arg2, ISocketMessageChannel arg3)
        {
            if (arg3 == null)
            {
                return;
            }
            if (arg2.EditedTimestamp == null)
            {
                return;
            }
            if (arg3.GetType() == typeof(SocketDMChannel))
            {
                return;
            }
            var oldmess = await arg1.GetOrDownloadAsync();

            GuildSetup setup;

            using (var db = new DatabaseContext())
            {
                setup = db.GuildSetups.FirstOrDefault(x => x.GuildId == (arg3 as SocketGuildChannel).Guild.Id);
                var message = db.LoggedMessages.FirstOrDefault(x => x.MessageId == oldmess.Id);
                message.IsEdited = true;
                message.Edits.Add(arg2.Content, arg2.EditedTimestamp.Value.DateTime);
                db.SaveChanges();
                if (db.GuildStarringSetups.FirstOrDefault(x => x.GuildId == (arg3 as SocketGuildChannel).Guild.Id)?.StarboardChannelId == arg3.Id)
                {
                    return;
                }
            }

            if (setup?.EditChannelId == 0)
            {
                return;
            }
            if (arg2.Content == "")
            {
                return;
            }

            await(arg3 as SocketGuildChannel).Guild.GetTextChannel(setup.EditChannelId).SendMessageAsync("", false, new EmbedBuilder
            {
                Title  = $"A message has been edited in {arg3.Name}!",
                Fields = new List <EmbedFieldBuilder> {
                    new EmbedFieldBuilder {
                        Name = "Before:", Value = $"```{oldmess.Content}```"
                    }, { new EmbedFieldBuilder {
                             Name = "After:", Value = $"```{arg2.Content}```"
                         } }
                },
                Footer = new EmbedFooterBuilder {
                    Text = $"Author: {arg2.Author.Username}", IconUrl = arg2.Author.GetAvatarUrl()
                },
                ThumbnailUrl = arg2.Author.GetAvatarUrl(),
                Color        = new Color(178, 224, 40),
                Timestamp    = arg2.EditedTimestamp
            }.WithUrl("http://heeeeeeeey.com/"));
        }
Exemplo n.º 2
0
 public bool isAdmin(SocketUser user, ISocketMessageChannel channel)
 {
     if (channel.GetType() == typeof(SocketDMChannel))
     {
         if ((server.GetUser(user.Id).GuildPermissions.Administrator || Admins.Contains(user.Id.ToString())))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     if (channel.GetType() == typeof(SocketTextChannel))
     {
         var stc = (SocketTextChannel)channel;
         if (stc.Guild == null || server == null)
         {
             Console.WriteLine("isAdmin check with one server being null!");
             return(false);
         }
         if (stc.Guild.Id != server.Id)
         {
             return(false);
         }
         if (server.GetUser(user.Id).GuildPermissions.Administrator)
         {
             return(true);
         }
         if (Admins.Contains(user.Id.ToString()))
         {
             return(true);
         }
         return(false);
     }
     else
     {
         Console.WriteLine("Got isAdmin check on channel type " + channel.GetType() + " this is atm unhandled");
         return(false);
     }
 }
Exemplo n.º 3
0
        private static async Task OnMessageDeleted(Cacheable <IMessage, ulong> cache, ISocketMessageChannel channel)
        {
            if (channel.GetType() != typeof(SocketTextChannel))
            {
                return;
            }

            SocketGuild guild = ((SocketTextChannel)channel).Guild;

            OliveGuild.GuildSetting setting = OliveGuild.Get(guild.Id).Setting;
            if (!setting.EnabledCategories.Contains(RequireCategoryEnable.CategoryType.Log) || !setting.LogChannelId.HasValue)
            {
                return;
            }
            SocketTextChannel c = guild.GetTextChannel(setting.LogChannelId.Value);

            EmbedBuilder emb = new EmbedBuilder
            {
                Title       = "메시지 삭제",
                Color       = new Color(255, 0, 0),
                Description = $"<#{channel.Id}> 채널에서 메시지({cache.Id})가 삭제됐어요\n",
                Timestamp   = DateTimeOffset.Now.ToKST()
            };

            if (cache.HasValue)
            {
                emb.WithAuthor($"{cache.Value.Author.Username}#{cache.Value.Author.Discriminator} ({cache.Value.Author.Id})", cache.Value.Author.GetAvatar());

                if (string.IsNullOrWhiteSpace(cache.Value.Content))
                {
                    emb.Description += "\n내용이 비어있어요";
                }
                else
                {
                    emb.AddField("내용", cache.Value.Content.Slice(512, out bool isApplied), true);
                    if (isApplied)
                    {
                        await c.SendFileAsync(cache.Value.Content.ToStream(), "before.txt", "");
                    }
                }
            }
            else
            {
                emb.WithAuthor("알 수 없음");

                emb.Description += "\n내용이 캐시에 저장되지 않았어요";
            }

            await c.SendMessageAsync(embed : emb.Build());
        }
Exemplo n.º 4
0
        public Command GetCommand(ISocketMessageChannel channel, User user, string[] args, string commandName)
        {
            commandName = "PikBot.Commands." + commandName + "Command";
            Type commandType = Type.GetType(commandName, true);

            Type[] paramTypes = new Type[] { channel.GetType(), user.GetType(), args.GetType() };

            ConstructorInfo constructor = commandType.GetConstructor(
                BindingFlags.Instance | BindingFlags.NonPublic,
                null, paramTypes, null);

            Object obj = constructor.Invoke(new object[] { channel, user, args });

            if (obj is Command)
            {
                return((Command)obj);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 5
0
        private async Task CheckInitThread(Cacheable <IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction arg3)
        {
            var usr = await arg2.GetUserAsync(arg3.UserId);

            if (usr.IsBot)
            {
                return;
            }

            if (arg2.GetType() != typeof(SocketDMChannel))
            {
                if (closingState.Keys.Any(x => x.Key == arg2.Id))
                {
                    var o = closingState.First(x => x.Key.Key == arg2.Id);
                    var m = await arg2.GetMessageAsync(o.Key.Value);

                    if (arg3.Emote.Equals(new Emoji("❌")))
                    {
                        o.Value.Stop();
                        o.Value.Dispose();
                        closingState.Remove(o.Key);
                        await m.DeleteAsync();
                    }
                }
                else if (WelcomeMessages.Contains(arg3.MessageId))
                {
                    if (arg3.Emote.Equals(new Emoji("❌")))
                    {
                        var m = await arg2.GetMessageAsync(arg3.MessageId);

                        await m.DeleteAsync();
                    }
                    if (arg3.Emote.Equals(new Emoji("✅")))
                    {
                        var ticket = CurrentTickets.Find(x => x.TicketChannel == arg2.Id);
                        var m      = await arg2.GetMessageAsync(arg3.MessageId);

                        var dmchan = await client.GetUser(ticket.UserID).GetOrCreateDMChannelAsync();

                        var gusr = usr as SocketGuildUser;
                        await m.DeleteAsync();

                        string tmsg = $"**[Staff] {(gusr.Nickname == null ? usr.ToString() : gusr.Nickname)}** - Hello! Swiss001 Support! How May I help you?";
                        await arg2.SendMessageAsync(tmsg);

                        await dmchan.SendMessageAsync(tmsg);
                    }
                }
                return;
            }

            var msg = await client.Rest.GetDMChannelAsync(arg2.Id).Result.GetMessageAsync(arg1.Id);

            if (isValidSetup(msg))
            {
                //checkmark
                if (arg3.Emote.Equals(new Emoji("✅")))
                {
                    if (client.GetGuild(Global.SwissGuildId).Users.Any(x => x.Id == usr.Id))
                    {
                        if (BlockedUsers.Any(x => x == usr.Id))
                        {
                            await arg2.SendMessageAsync("", false, new EmbedBuilder()
                            {
                                Title       = "You are blocked!",
                                Description = "Looks like your blocked from creating support tickets :/",
                                Color       = Color.Red
                            }.Build());

                            await msg.DeleteAsync();

                            return;
                        }
                        else
                        {
                            await msg.DeleteAsync();

                            var tmpmsg = await arg2.SendMessageAsync("**Creating support ticket with the staff team...**");

                            RestDMChannel rChan = (RestDMChannel)await client.Rest.GetDMChannelAsync(arg2.Id);

                            var msgs = await rChan.GetMessagesAsync(arg1.Id, Direction.Before, 1).FlattenAsync();
                            await CreateNewTicket(arg2, usr, msgs.First().Content);

                            await tmpmsg.ModifyAsync(x => x.Embed = new EmbedBuilder()
                            {
                                Title       = "Congrats! You are now talking with staff!",
                                Description = "Please note staff **Can** take moderation action for anything you say in a ticket. The same rules apply as the server.\n_This ticket may also be archived and used for training purposes._",
                                Color       = Color.Green
                            }.Build());
                        }
                    }
                    else
                    {
                        await usr.SendMessageAsync("", false, new EmbedBuilder()
                        {
                            Title       = "Sorry... :(",
                            Description = "The staff team does not accept tickets from users who are not in the server.",
                            Color       = Color.Red
                        }.Build());
                    }
                }
                else if (arg3.Emote.Equals(new Emoji("❌"))) // xmark
                {
                    await msg.DeleteAsync();
                }
            }
        }
Exemplo n.º 6
0
        public static async Task OnMessageUpdated(Cacheable <IMessage, ulong> cache, SocketMessage msg, ISocketMessageChannel channel)
        {
            if (channel.GetType() != typeof(SocketTextChannel))
            {
                return;
            }

            SocketGuild guild = ((SocketTextChannel)channel).Guild;

            OliveGuild.GuildSetting setting = OliveGuild.Get(guild.Id).Setting;
            if (!setting.EnabledCategories.Contains(RequireCategoryEnable.CategoryType.Log) || !setting.LogChannelId.HasValue)
            {
                return;
            }
            SocketTextChannel c = guild.GetTextChannel(setting.LogChannelId.Value);

            EmbedBuilder emb = new EmbedBuilder
            {
                Title       = "메시지 수정",
                Color       = new Color(255, 255, 0),
                Description = $"<#{channel.Id}> 채널에서 [메시지]({msg.GetJumpUrl()})가 수정됐어요\n",
                Timestamp   = DateTimeOffset.Now.ToKST()
            };

            emb.WithAuthor(msg.Author);

            if (cache.HasValue)
            {
                if (cache.Value.Content == msg.Content)
                {
                    return;
                }

                if (string.IsNullOrWhiteSpace(cache.Value.Content))
                {
                    emb.Description += "\n수정 전 내용이 비어있어요";
                }
                else
                {
                    emb.AddField("수정 전 내용", cache.Value.Content.Slice(512, out bool isApplied), true);
                    if (isApplied)
                    {
                        await c.SendFileAsync(msg.Content.ToStream(), "before.txt", "");
                    }
                }
            }
            else
            {
                emb.Description += "\n수정 전 내용은 캐시에 저장되지 않았어요";
            }

            if (string.IsNullOrWhiteSpace(msg.Content))
            {
                emb.Description += "\n수정 후 내용이 비어있어요";
            }
            else
            {
                emb.AddField("수정 후 내용", msg.Content.Slice(512, out bool isApplied), true);
                if (isApplied)
                {
                    await c.SendFileAsync(msg.Content.ToStream(), "after.txt", "");
                }
            }

            await c.SendMessageAsync(embed : emb.Build());
        }