Beispiel #1
0
        public async Task Report()
        {
            string last = await Program.p.GetDb().GetLast(Context.Guild.Id);

            if (await Program.p.GetDb().IsBan(Context.User.Id.ToString()))
            {
                await ReplyAsync(Sentences.IsBanned(Context.Guild.Id));
            }
            else if (last != null)
            {
                string[] content = last.Split('|');
                await Program.p.GetDb().DeleteLast(Context.Guild.Id);

                await Program.p.client.GetGuild(Sentences.refGuild).GetTextChannel(Sentences.refChannel).SendMessageAsync(
                    "", false, new EmbedBuilder
                {
                    Color       = Color.Red,
                    Title       = "Report of user " + content[0] + " by " + Context.User.Id + ", chan NSFW: " + ((ITextChannel)Context.Channel).IsNsfw,
                    Description = "<" + content[1] + "> the " + DateTime.Now.ToString("dd/MM/yy HH:mm:ss")
                }.Build());

                await((await(await Context.Guild.GetTextChannelAsync(Convert.ToUInt64(content[2]))).GetMessageAsync(Convert.ToUInt64(content[3]))) as IUserMessage).ModifyAsync(
                    x => x.Embed = new EmbedBuilder {
                    Color = Color.Red, Title = Sentences.Reported(Context.Guild.Id)
                }.Build());
                await ReplyAsync(Sentences.ReportDone(Context.Guild.Id));
            }
            else
            {
                await ReplyAsync(Sentences.NoReport(Context.Guild.Id));
            }
        }
Beispiel #2
0
 private EmbedFieldBuilder EditField(EmbedField field, string emoteName, bool addReaction, int counter, int id, ulong guildId)
 {
     if (counter == id)
     {
         bool   found          = false;
         string finalStr       = "";
         string emoteSmallName = emoteName;
         Match  match          = Regex.Match(emoteSmallName, "<(:[^:]+:)[0-9]+>");
         if (match.Success)
         {
             emoteSmallName = match.Groups[1].Value;
         }
         foreach (string s in field.Value.Split(new string[] { Environment.NewLine }, StringSplitOptions.None))
         {
             if (s == Sentences.NothingYet(guildId))
             {
                 continue;
             }
             string[] emote = s.Split(' ');
             if (emote[0] == emoteName || emote[0] == emoteSmallName)
             {
                 int newNb = Convert.ToInt32(emote[1].Substring(1, emote[1].Length - 1)) + ((addReaction) ? (1) : (-1));
                 if (newNb > 0)
                 {
                     finalStr += emote[0] + " x" + newNb + Environment.NewLine;
                 }
                 found = true;
             }
             else
             {
                 finalStr += s + Environment.NewLine;
             }
         }
         if (!found)
         {
             finalStr += emoteName + " x1" + Environment.NewLine;
         }
         if (finalStr == "")
         {
             finalStr = Sentences.NothingYet(guildId);
         }
         return(new EmbedFieldBuilder()
         {
             Name = field.Name,
             Value = finalStr
         });
     }
     return(new EmbedFieldBuilder()
     {
         Name = field.Name,
         Value = field.Value
     });
 }
Beispiel #3
0
        /// <summary>
        /// Check images in message and send them in gate if necessary
        /// </summary>
        /// <param name="arg">SocketMessage received from HandleCommandAsync</param>
        /// <param name="msg">User message</param>
        private async Task SendMessageGate(SocketMessage arg, SocketUserMessage msg)
        {
            string url = GetImageUrl(msg);

            if (url != null)
            {
                ulong           guildId = (arg.Channel as ITextChannel).GuildId;
                RestUserMessage waitMsg = await arg.Channel.SendMessageAsync(Sentences.WaitMsg(guildId));

                if (!await db.IsBan(arg.Author.Id.ToString()))
                {
                    bool isNsfw = (arg.Channel as ITextChannel).IsNsfw;
                    if (await IsSfw(url, isNsfw))
                    {
                        TimeSpan?waitValue = CanSendImage(guildId);
                        if (waitValue == null || waitValue.Value.TotalSeconds < 0)
                        {
                            if (timeLastSent.ContainsKey(guildId))
                            {
                                timeLastSent[guildId] = DateTime.Now;
                            }
                            else
                            {
                                timeLastSent.Add(guildId, DateTime.Now);
                            }
                            List <string> ids = db.GetAllGuilds(guildId, isNsfw, out _, out _);
                            if (ids.Count == 0)
                            {
                                await waitMsg.ModifyAsync(x => x.Content = Sentences.NoChan(guildId));
                            }
                            else
                            {
                                await SendImageToServer(ids, arg, url, guildId, waitMsg);
                            }
                        }
                        else
                        {
                            await waitMsg.ModifyAsync(x => x.Content = Sentences.WaitImage(guildId, TimeSpanToString(guildId, waitValue.Value)));
                        }
                    }
                    else
                    {
                        await waitMsg.ModifyAsync(x => x.Content = Sentences.NsfwImage(guildId) + ((isNsfw) ? (" " + Sentences.WrongNsfw(guildId)) : ("")));
                    }
                }
                else
                {
                    await waitMsg.ModifyAsync(x => x.Content = Sentences.IsBannedImage(guildId));
                }
                await IncreaseCommandReceived();
            }
        }
Beispiel #4
0
        public async Task Infos()
        {
            EmbedBuilder embed = new EmbedBuilder
            {
                Color = Color.Purple
            };

            embed.AddField(Sentences.Author(Context.Guild.Id), "Zirk#0001");
            embed.AddField(Sentences.Uptime(Context.Guild.Id), Program.TimeSpanToString(Context.Guild.Id, DateTime.Now.Subtract(p.startTime)));
            embed.AddField(Sentences.LatestVersion(Context.Guild.Id), new FileInfo(Assembly.GetEntryAssembly().Location).LastWriteTimeUtc.ToString(Sentences.DateTimeFormat(Context.Guild.Id)) + " UTC+0", true);
            embed.AddField("GitHub", "https://github.com/Xwilarg/Lania");
            embed.AddField(Sentences.InvitationLink(Context.Guild.Id), Sentences.inviteLink);
            await ReplyAsync("", false, embed.Build());
        }
Beispiel #5
0
 public async Task CloseGate()
 {
     if (!CanModify(Context.User, Context.Guild.OwnerId))
     {
         await ReplyAsync(Sentences.OnlyManage(Context.Guild.Id));
     }
     else if (await Close(Context.Guild.Id))
     {
         await ReplyAsync(Sentences.GateClosed(Context.Guild.Id));
     }
     else
     {
         await ReplyAsync(Sentences.NoGate(Context.Guild.Id));
     }
 }
Beispiel #6
0
        public async Task Ban(string id, params string[] reason)
        {
            if (Context.User.Id != Sentences.ownerId)
            {
                await ReplyAsync(Sentences.OnlyUser(Context.Guild.Id, Sentences.ownerName));

                return;
            }
            bool   banned      = false;
            string finalReason = string.Join(" ", reason);

            if (await Program.p.GetDb().IsBan(id))
            {
                await ReplyAsync(Sentences.AlreadyBanned(Context.Guild.Id));
            }
            else
            {
                await Program.p.GetDb().Ban(id, finalReason);
                await ReplyAsync(Sentences.Banned(Context.Guild.Id));

                banned = true;
            }
            int  i     = 0;
            bool wasPm = false;

            foreach (SocketGuild sg in Program.p.client.Guilds)
            {
                if (banned && !wasPm)
                {
                    SocketGuildUser user = sg.Users.ToList().Find(x => x.Id.ToString() == id);
                    if (user != null)
                    {
                        await user.SendMessageAsync(Sentences.UserBanned(Context.Guild.Id) + finalReason);

                        wasPm = true;
                    }
                }
                if (sg.OwnerId.ToString() == id)
                {
                    i++;
                    await Close(sg.Id);
                }
            }
            if (i > 0)
            {
                await ReplyAsync(i + Sentences.GateClosedBan(Context.Guild.Id));
            }
        }
Beispiel #7
0
 public async Task OpenGate()
 {
     if (!CanModify(Context.User, Context.Guild.OwnerId))
     {
         await ReplyAsync(Sentences.OnlyManage(Context.Guild.Id));
     }
     else if (await Program.p.GetDb().IsBan(Context.User.Id.ToString()))
     {
         await ReplyAsync(Sentences.IsBanned(Context.Guild.Id));
     }
     else
     {
         await Program.p.GetDb().OpenGate(Context.Guild.Id, Context.Channel.Id);
         await ReplyAsync(Sentences.GateOpened(Context.Guild.Id));
     }
 }
Beispiel #8
0
 /// <summary>
 /// Return a string given a TimeSpan
 /// </summary>
 /// <param name="ts">The TimeSpan to transform</param>
 /// <returns>The string wanted</returns>
 public static string TimeSpanToString(ulong guildId, TimeSpan ts)
 {
     if (ts.Days > 0)
     {
         return(Sentences.TimeDays(guildId, ts.Days.ToString(), ts.Hours.ToString(), ts.Minutes.ToString(), ts.Seconds.ToString()));
     }
     if (ts.Hours > 0)
     {
         return(Sentences.TimeHours(guildId, ts.Hours.ToString(), ts.Minutes.ToString(), ts.Seconds.ToString()));
     }
     if (ts.Minutes > 0)
     {
         return(Sentences.TimeMinutes(guildId, ts.Minutes.ToString(), ts.Seconds.ToString()));
     }
     return(Sentences.TimeSeconds(guildId, ts.Seconds.ToString()));
 }
Beispiel #9
0
        public async Task Language(string language = null)
        {
            if (Context.User.Id != Context.Guild.OwnerId)
            {
                await ReplyAsync(Sentences.OnlyUser(Context.Guild.Id, (await Context.Guild.GetOwnerAsync()).ToString()));

                return;
            }
            if (language == null)
            {
                await ReplyAsync(Sentences.LanguageHelp(Context.Guild.Id));

                return;
            }
            string key = null;

            language = language.ToLower();
            var alternate = p.GetTranslationKeyAlternate();

            if (alternate.ContainsKey(language))
            {
                key = language;
            }
            else
            {
                foreach (var k in alternate)
                {
                    if (k.Value.Contains(language))
                    {
                        key = k.Key;
                        break;
                    }
                }
            }
            if (key == null)
            {
                await ReplyAsync(Sentences.InvalidLanguage(Context.Guild.Id));
            }
            else
            {
                await Program.p.GetDb().SetLanguage(Context.Guild.Id, key);

                Program.p.GetLanguages()[Context.Guild.Id] = key;
                await ReplyAsync(Sentences.LanguageChanged(Context.Guild.Id));
            }
        }
Beispiel #10
0
        public async Task StatsGate()
        {
            IEnumerable <dynamic> emotes = await Program.p.GetDb().GetEmotes(Context.Guild.Id);

            if (emotes != null)
            {
                Dictionary <string, int> allEmotes = new Dictionary <string, int>();
                foreach (var f in emotes)
                {
                    Match match = Regex.Match(f.ToString(), "\"([^\"]+)\": \"([0-9]+)\"");
                    if (match.Groups[1].Value != "id")
                    {
                        allEmotes.Add(match.Groups[1].Value, int.Parse(match.Groups[2].Value));
                    }
                }
                if (allEmotes.Count == 0)
                {
                    await ReplyAsync(Sentences.NoEmote(Context.Guild.Id));
                }
                else
                {
                    string finalStr = "";
                    int    counter  = 10;
                    while (counter > 0 && allEmotes.Count > 0)
                    {
                        KeyValuePair <string, int>?biggest = null;
                        foreach (var kv in allEmotes)
                        {
                            if (biggest == null || kv.Value > biggest.Value.Value)
                            {
                                biggest = kv;
                            }
                        }
                        finalStr += biggest.Value.Key + " x" + biggest.Value.Value + Environment.NewLine;
                        allEmotes.Remove(biggest.Value.Key);
                        counter--;
                    }
                    await ReplyAsync(Sentences.MyEmotes(Context.Guild.Id) + Environment.NewLine + finalStr);
                }
            }
            else
            {
                await ReplyAsync(Sentences.NoEmote(Context.Guild.Id));
            }
        }
Beispiel #11
0
        public async Task StatusGate()
        {
            string finalStr = "";
            string id       = await Program.p.GetDb().GetGateChan(Context.Guild.Id);

            if (id != null)
            {
                finalStr += Sentences.GateChannel(Context.Guild.Id, "<#" + id + ">");
            }
            else
            {
                await ReplyAsync(Sentences.NoGateHere(Context.Guild.Id));

                return;
            }
            int total, relative, read;

            relative = Program.p.GetDb().GetAllGuilds(Context.Guild.Id, (await Context.Guild.GetTextChannelAsync(ulong.Parse(id))).IsNsfw, out total, out read).Count;
            await ReplyAsync(finalStr + Environment.NewLine + Sentences.NbGates(Context.Guild.Id, total.ToString(), read.ToString(), relative.ToString()));
        }
Beispiel #12
0
        /// <summary>
        /// Send image to 3 random guilds and write emote status in channel
        /// </summary>
        /// <param name="ids">ids of all guilds available</param>
        /// <param name="arg">SocketMessage got by HandleCommandAsync</param>
        /// <param name="url">url to image</param>
        private async Task SendImageToServer(List <string> ids, SocketMessage arg, string url, ulong guildId, RestUserMessage waitMsg)
        {
            bool isLast;
            List <ITextChannel> chans = SendImages(ids, (arg.Channel as ITextChannel).IsNsfw, guildId, out isLast);
            EmbedBuilder        embed = new EmbedBuilder()
            {
                Description = Sentences.FileSent(guildId, chans.Count.ToString())
            };

            for (int y = 0; y < chans.Count; y++)
            {
                embed.AddField("#" + (y + 1) + ((y == 0 && isLast) ? (" " + Sentences.LastImage(guildId)) : ("")), Sentences.NothingYet(guildId));
            }
            ulong msgId = waitMsg.Id;
            await waitMsg.ModifyAsync((x) => { x.Content = ""; x.Embed = embed.Build(); });

            List <ImageData> datas = new List <ImageData>();

            foreach (ITextChannel chan in chans)
            {
                ulong msgDest = (await chan.SendMessageAsync("", false, new EmbedBuilder()
                {
                    ImageUrl = url,
                    Title = Sentences.ImageReceived(chan.GuildId),
                    Footer = new EmbedFooterBuilder()
                    {
                        Text = Sentences.EmoteHelp(chan.GuildId)
                    }
                }.Build())).Id;
                ITextChannel textChan = (arg.Channel as ITextChannel);
                datas.Add(new ImageData(textChan.GuildId, arg.Channel.Id, msgId, chan.GuildId, chan.Id, msgDest, textChan.IsNsfw));
            }
            int counter = 0;

            foreach (ImageData data in datas)
            {
                await db.SendImage(data, counter, url, guildId);

                counter++;
            }
        }
Beispiel #13
0
        private Task LogError(LogMessage msg)
        {
            if (ravenClient == null)
            {
                Log(msg);
            }
            else
            {
                ravenClient.Capture(new SentryEvent(msg.Exception));
            }
            CommandException ce = msg.Exception as CommandException;

            if (ce != null)
            {
                ce.Context.Channel.SendMessageAsync("", false, new EmbedBuilder()
                {
                    Color       = Color.Red,
                    Title       = msg.Exception.InnerException.GetType().ToString(),
                    Description = Sentences.Error(ce.Context.Guild.Id, msg.Exception.InnerException.Message)
                }.Build());
            }
            return(Task.CompletedTask);
        }
Beispiel #14
0
 public async Task Help()
 {
     await ReplyAsync("", false, new EmbedBuilder { Color = Color.Purple, Description = Sentences.Help(Context.Guild.Id) }.Build());
 }