Esempio n. 1
0
        public async Task SearchAsync([Remainder] string video)
        {
            if (!(await Access("search")))
            {
                return;
            }

            SLog logger = new SLog("search", Context);

            try
            {
                ConstVariables.CDiscord guild = Module.ConstVariables.CServer[Context.Guild.Id];

                EmbedBuilder builder = new EmbedBuilder();
                builder.WithFooter(Context.Guild.Name, Context.Guild.IconUrl)
                .WithThumbnailUrl("https://media.discordapp.net/attachments/462236317926031370/473478987126013952/yt_logo_rgb_dark.png");

                var youtubeService = new YouTubeService(new BaseClientService.Initializer()
                {
                    ApiKey          = "AIzaSyDIuH33zi6aod6jSHm31V1VIVKYIIGxvEo",
                    ApplicationName = this.GetType().ToString()
                });

                var SearchVideo = youtubeService.Search.List("snippet");
                SearchVideo.Q          = video;
                SearchVideo.Type       = "video";
                SearchVideo.ChannelId  = "UCScLnRAwAT2qyNcvaFSFvYA";
                SearchVideo.MaxResults = 5;

                var SearchResult = await SearchVideo.ExecuteAsync();

                int    i      = 1;
                string strock = "";

                foreach (var Search in SearchResult.Items)
                {
                    strock += $"{i++}: {Search.Snippet.Title}\r\nurl:https://www.youtube.com/video/" + Search.Id.VideoId + "\r\n";
                }


                builder.AddField("YouTube video search", strock)
                .WithColor(ConstVariables.InfoColor);

                await Context.Channel.SendMessageAsync("", embed : builder.Build());

                logger._addcondition = $" is Content '{video}'";
            }
            catch (Exception e)
            {
                await ReplyAsync("Ошибка во время выполнения! Обратитесь к админестратору!");

                logger._exception = e;
            }

            logger.PrintLog();
        }
Esempio n. 2
0
        public async Task HelpAsync()
        {
            if (!(await Access("help")))
            {
                return;
            }

            SLog logger = new SLog("Help", Context);

            try
            {
                SocketGuildUser user = Context.Guild.GetUser(Context.User.Id);

                ConstVariables.CDiscord guild = ConstVariables.CServer[Context.Guild.Id];

                EmbedBuilder builder = new EmbedBuilder();

                bool IsRole = false;

                foreach (var role in user.Roles)
                {
                    if (guild.EntryRole(role.Id))
                    {
                        IsRole = true;
                        break;
                    }
                }

                string TitlList = "Префикс команд для бота 'sh!' или 'Sh!'";

                builder.AddField("Параметры", "[] - обязательно \r\n<> - не обязательно")
                .WithTitle(TitlList)
                .AddField("Group: Default", Module.ConstVariables.UTHelp, true)
                .WithColor(Color.Orange)
                .WithFooter(Context.Guild.Name, Context.Guild.IconUrl);

                if (IsRole)
                {
                    builder.AddField("Group: Admin", Module.ConstVariables.ATHelp, true);
                }

                if (Context.User.Id == ConstVariables.DateBase.OwnerID)
                {
                    string own = $"1: allnews\r\n";
                    own += $"2: debug\r\n";
                    own += $"3: selecttriggerdefault";
                    builder.AddField("Group: Owner", own, true);
                }

                logger._addcondition = $" is IsRole {IsRole}";

                await Context.Channel.SendMessageAsync($"{Context.Message.Author.Mention},", false, builder.Build());
            }
            catch (Exception e)
            {
                await ReplyAsync("Ошибка во время выполнения! Обратитесь к админестратору!");

                logger._exception = e;
            }

            logger.PrintLog();
        }
Esempio n. 3
0
        public async Task AllNewsAsync([Remainder] string mess)
        {
            SLog logger = new SLog("AllNews", Context);

            string URL = ConstVariables.Patch + "Base/news26052017.jpg";

            bool islocalfile = true;

            if (mess.IndexOf("image:") == 0)
            {
                mess = mess.Remove(0, 6);
                int tchk = mess.IndexOf(';');
                URL         = mess.Substring(0, tchk);
                mess        = mess.Remove(0, tchk + 2);
                islocalfile = false;
            }

            var result = await Context.Channel.SendMessageAsync("Sayary, жди. Начата рассылка");

            foreach (var server in ConstVariables.CServer)
            {
                if (server.Value.DefaultChannelNewsId == 0)
                {
                    continue;
                }

                try
                {
                    ConstVariables.CDiscord guild = server.Value;

                    if (ConstVariables.ThisTest)
                    {
                        if (server.Value.GuildId != 435485527156981770)
                        {
                            continue;
                        }

                        if (islocalfile)
                        {
                            await guild.GetDefaultNewsChannel().SendFileAsync(URL, " ");
                        }
                        else
                        {
                            await guild.GetDefaultNewsChannel().SendMessageAsync(URL);
                        }

                        await guild.GetDefaultNewsChannel().SendMessageAsync(mess);

                        await guild.GetDefaultNewsChannel().SendMessageAsync("Автор: " + Context.User.Mention);

                        break;
                    }
                    else
                    {
                        if (islocalfile)
                        {
                            await guild.GetDefaultNewsChannel().SendFileAsync(URL, " ");
                        }
                        else
                        {
                            await guild.GetDefaultNewsChannel().SendMessageAsync(URL);
                        }

                        await guild.GetDefaultNewsChannel().SendMessageAsync(mess);

                        await guild.GetDefaultNewsChannel().SendMessageAsync("Автор: " + Context.User.Mention);
                    }
                }
                catch (Exception e)
                {
                    logger._exception = e;
                }
            }

            try
            {
                await Context.Message.DeleteAsync();

                await result.DeleteAsync();
            }
            catch (Exception e)
            {
                logger._exception = e;
            }

            logger.PrintLog();
        }
Esempio n. 4
0
        public async Task NewsAsync([Remainder] string mess)
        {
            if (!(await Access("news")))
            {
                return;
            }

            SLog logger = new SLog("News", Context);

            string URL         = "Base/news26052017.jpg";
            bool   islocalfile = true;

            if (mess.IndexOf("image:") == 0)
            {
                mess = mess.Remove(0, 6);
                int tchk = mess.IndexOf(';');
                URL         = mess.Substring(0, tchk);
                mess        = mess.Remove(0, tchk + 2);
                islocalfile = false;
            }

            var result = await Context.Channel.SendMessageAsync("Начата рассылка!\n Ждите, если это сообщение не пропадет, то напишите Sayary.");

            var serv = ConstVariables.CServer[Context.Guild.Id];

            foreach (var server in ConstVariables.CServer)
            {
                if (server.Value.DefaultChannelNewsId == 0)
                {
                    continue;
                }

                try
                {
                    ConstVariables.CDiscord guild = server.Value;

                    if (ConstVariables.ThisTest)
                    {
                        if (server.Value.GuildId != 435485527156981770)
                        {
                            continue;
                        }

                        if (islocalfile)
                        {
                            await guild.GetDefaultNewsChannel().SendFileAsync(URL, " ");
                        }
                        else
                        {
                            await guild.GetDefaultNewsChannel().SendMessageAsync(URL);
                        }

                        await guild.GetDefaultNewsChannel().SendMessageAsync(mess);

                        await guild.GetDefaultNewsChannel().SendMessageAsync("Автор: " + Context.User.Mention);

                        break;
                    }
                    else if (Context.User.Id == ConstVariables.DateBase.OwnerID)
                    {
                        if (islocalfile)
                        {
                            await guild.GetDefaultNewsChannel().SendFileAsync(URL, " ");
                        }
                        else
                        {
                            await guild.GetDefaultNewsChannel().SendMessageAsync(URL);
                        }

                        await guild.GetDefaultNewsChannel().SendMessageAsync(mess);

                        await guild.GetDefaultNewsChannel().SendMessageAsync("Автор: " + Context.User.Mention);
                    }
                    else if (Context.Guild.Id == server.Value.GuildId)
                    {
                        if (islocalfile)
                        {
                            await guild.GetDefaultNewsChannel().SendFileAsync("Base/LegioNews2.png", " ");
                        }
                        else
                        {
                            await guild.GetDefaultNewsChannel().SendMessageAsync(URL);
                        }

                        await guild.GetDefaultNewsChannel().SendMessageAsync(mess);

                        await guild.GetDefaultNewsChannel().SendMessageAsync("Автор: " + Context.User.Mention);

                        break;
                    }
                }
                catch (Exception e)
                {
                    logger._exception = e;
                }
            }

            try
            {
                await Context.Message.DeleteAsync();

                await result.DeleteAsync();
            }
            catch
            {
                Console.WriteLine("Ошибка доступа!");
            }

            logger.PrintLog();
        }
Esempio n. 5
0
        public async Task StatusAsync()
        {
            if (!(await Access("status")))
            {
                return;
            }

            SLog logger = new SLog("Status", Context);

            string SqlRequestRole    = $"SELECT [RoleId] FROM [Role] WHERE [GuildId] = {Context.Guild.Id}";
            string SqlRequestChannel = $"SELECT [ChannelId] FROM [Channel] WHERE [GuildId] = {Context.Guild.Id}";

            ConstVariables.CDiscord guild = ConstVariables.CServer[Context.Guild.Id];

            EmbedBuilder builder = new EmbedBuilder();

            string role = "";

            string channel = "";

            builder.WithTitle("the status of the bot")
            .WithFooter(Context.Guild.Name, Context.Guild.IconUrl)
            .WithAuthor(Context.User.Username, Context.User.GetAvatarUrl())
            .AddField("Guild", Context.Guild.Name, true)
            .AddField("Resurs", guild.CountRes + "/" + guild.Restruction, true)
            .WithColor(ConstVariables.AdminColor);

            int i = 1;

            try
            {
                using (SqlConnection connect = new SqlConnection(ConstVariables.DateBase.ConnectionStringKey))
                {
                    connect.Open();
                    SqlCommand command = new SqlCommand(SqlRequestRole, connect);
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                role += $"{i++}: **{Context.Guild.GetRole((ulong)reader.GetInt64(0)).Name}**\r\n";
                            }
                        }
                        else
                        {
                            throw new Exception($"Ошибка в чтении ролей сервера: {Context.Guild.Id}");
                        }
                    }

                    i = 1;

                    command.CommandText = SqlRequestChannel;
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                channel += $"{i++}: **{Context.Guild.GetChannel((ulong)reader.GetInt64(0)).Name}**\r\n";
                            }
                        }
                        else
                        {
                            throw new Exception($"Ошибка в чтении каналов сервера: {Context.Guild.Id}");
                        }
                    }
                }

                builder.AddField("Roles", role, true)
                .AddField("Channels", channel, true)
                .AddField("Версия бота", Base.Resource.VersionBot, true)
                .AddField("Defaul channel", Context.Guild.GetTextChannel(guild.DefaultChannelId).Mention, true)
                .AddField("Default channel for news", Context.Guild.GetTextChannel(guild.DefaultChannelNewsId).Mention, true)
                .AddField("Guild Id", guild.GuildId, true);

                await Context.Channel.SendMessageAsync("", false, builder.Build());
            }
            catch (Exception e)
            {
                await ReplyAsync("Ошибка чтения! Обратитесь к администратору!");

                logger._exception = e;
            }
            logger.PrintLog();
        }
Esempio n. 6
0
        private static async void Youtube(object obj)
        {
            while (DiscordAPI._Client.ConnectionState != ConnectionState.Connected)
            {
                Thread.Sleep(1000);
            }

            Thread.Sleep(2000);

            ConstVariables.Mess?.Invoke(" Запуск потока: YouTubeStream;");
            ConstVariables.Logger.Info("Запуск потока: YouTubeStream;");

            var youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                ApiKey          = Base.Resource.ApiKeyToken,
                ApplicationName = "Legion-kun"
            });

            string SqlExpressionStreams = "sp_GetAccountStreams";

            try
            {
                do
                {
                    if (ConstVariables.ControlFlow)
                    {
                        Thread.Sleep(60000);
                        continue;
                    }

                    List <Stream> streams = new List <Stream>();

                    using (SqlConnection connect = new SqlConnection(ConstVariables.DateBase.ConnectionStringKey))
                    {
                        try
                        {
                            connect.Open();
                            using (SqlCommand command = new SqlCommand(SqlExpressionStreams, connect))
                            {
                                SqlDataReader reader = command.ExecuteReader();

                                if (reader.HasRows)
                                {
                                    while (reader.Read())
                                    {
                                        Stream NewStr = new Stream();
                                        NewStr.id        = reader.GetInt32(0);
                                        NewStr.channelid = reader.GetString(1);
                                        NewStr.videoid   = reader.GetString(2);
                                        NewStr.ison      = reader.GetBoolean(3);
                                        NewStr.Name      = reader.GetString(4);
                                        NewStr.GuildsId  = reader.GetString(5);
                                        if (NewStr.ison)
                                        {
                                            streams.Add(NewStr);
                                        }
                                    }
                                    reader.Close();
                                }
                                else
                                {
                                    throw new Exception($"Ошибка чтения");
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            ConstVariables.Logger.Error($"YutubeSearch, errorrs: '{e}'");
                        }
                    }

                    foreach (Stream str in streams)
                    {
                        SearchResource.ListRequest Account = youtubeService.Search.List("snippet");
                        Account.Type       = "video";
                        Account.EventType  = SearchResource.ListRequest.EventTypeEnum.Live;
                        Account.ChannelId  = str.channelid;
                        Account.MaxResults = 1;
                        String[] guilds = str.GuildsId.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);

                        SearchListResponse searchList = null;

                        try
                        {
                            searchList = await Account.ExecuteAsync();
                        }
                        catch (Exception e)
                        {
                            ConstVariables.Logger.Error($"YoutubeSearch. is errors :{e}");
                            Thread.Sleep(60000);
                            continue;
                        }

                        if (searchList.Items.Count == 0)
                        {
                            continue;
                        }

                        SearchResult stream = searchList.Items[0];

                        if (stream.Id.VideoId == str.videoid)
                        {
                            continue;
                        }

                        if (ConstVariables.ThisTest)
                        {
                            ConstVariables.CDiscord guild   = ConstVariables.CServer[435485527156981770];
                            SocketTextChannel       channel = guild.GetGuild().GetTextChannel(444152623319482378);

                            EmbedBuilder Live = new EmbedBuilder();
                            Live.AddField("Новости", $"Найден стрим у {str.Name}!")
                            .WithColor(ConstVariables.InfoColor);

                            await channel.SendMessageAsync("", embed : Live.Build());

                            await channel.SendMessageAsync("https://www.youtube.com/video/" + stream.Id.VideoId);
                        }
                        else
                        {
                            foreach (var key in ConstVariables.CServer)
                            {
                                if (guilds.Length != 0)
                                {
                                    foreach (var par in guilds)
                                    {
                                        if ((ulong)Convert.ToInt64(par) == key.Key)
                                        {
                                            continue;
                                        }
                                    }
                                }

                                try
                                {
                                    SocketTextChannel channel = null;
                                    if (key.Value.DefaultChannelNewsId == 0)
                                    {
                                        channel = key.Value.GetDefaultChannel();
                                    }
                                    else
                                    {
                                        channel = key.Value.GetGuild().GetTextChannel(key.Value.DefaultChannelNewsId);
                                    }

                                    EmbedBuilder Live = new EmbedBuilder();
                                    Live.AddField("Новости", $"Найден стрим у {str.Name}!")
                                    .WithColor(ConstVariables.InfoColor);

                                    await key.Value.GetDefaultNewsChannel().SendMessageAsync("@here", embed: Live.Build());

                                    await key.Value.GetDefaultNewsChannel().SendMessageAsync("https://www.youtube.com/video/" + stream.Id.VideoId);

                                    //ConstVariables.logger.Info($"is guild {key.Value.Name} is channel {channel.Name}");
                                }
                                catch (Exception e)
                                {
                                    ConstVariables.Logger.Error($"is guild {key.Value.Name} is error {e}");
                                    ConstVariables.Mess($"Youtube: is guild: {key.Key} {e}");
                                }
                            }
                        }

                        ConstVariables.UpdVideo(str.id, stream.Id.VideoId);
                    }

                    Thread.Sleep(60000);
                } while (true);
            }
            catch (Exception ex)
            {
                ConstVariables.Logger.Error($"Automatic(YouTube): Errorr {ex}");
            }
        }