Esempio n. 1
0
 private async Task _client_UserLeft(SocketGuildUser user)
 {
     if (user.Guild.Name == "Discord-BOT-Tutorial")
     {
         if (_client.GetChannel(GuildsData.FindGuildConfig(user.Guild.Id).LogChannelID) is SocketTextChannel discordBotTutorialGeneral)
         {
             await discordBotTutorialGeneral.SendMessageAsync(
                 $"{user.Username} ({user.Id}) left **{user.Guild.Name}**!");
         }
     }
 }
Esempio n. 2
0
 public Context(DiscordSocketClient client, SocketUserMessage message, IServiceProvider provider) : base(client, message)
 {
     Client      = client;
     Message     = message;
     _provider   = provider;
     User        = message.Author;
     Channel     = message.Channel;
     Guild       = (message.Channel as SocketGuildChannel)?.Guild;
     GuildConfig = GuildsData.FindOrCreateGuildConfig(Guild);
     // _userAccount = UserAccounts.CreateUserAccount(message.Author.Id, true);
 }
Esempio n. 3
0
        private static async void OnTimerTicked(object args, ElapsedEventArgs e)
        {
            await Utilities.Log("Timer Event", "Tick! " + Global.Client.ConnectionState, LogSeverity.Debug);

            await Global.Client.SetGameAsync(Config.BotConfig.Playing, "https://www.twitch.tv/alexlyee", ActivityType.Streaming);

            await Global.Client.SetStatusAsync(Config.BotConfig.Status);

            foreach (GuildConfig c in GuildsData.GetConfigs())
            {
                SocketTextChannel channel = Global.Client.GetGuild(c.Id).GetTextChannel(c.LogChannelID);
            }
        }
Esempio n. 4
0
        public async Task HandleCommandAsync(SocketMessage s)
        {
            if (!(s is SocketUserMessage msg))
            {
                return;
            }
            var context = new SocketCommandContext(_client, msg);
            int argPos  = 0;

            if (msg.HasStringPrefix(GuildsData.FindOrCreateGuildConfig(context.Guild).Prefix, ref argPos) ||
                msg.HasMentionPrefix(_client.CurrentUser, ref argPos))
            {
                await Utilities.Log(MethodBase.GetCurrentMethod(), "Command detected.", Discord.LogSeverity.Verbose);

                /*
                 * await Utilities.Log(MethodBase.GetCurrentMethod(), UserAccounts.GetAccount(_client.CurrentUser.Id, true).ToString());
                 * if (UserAccounts.GetAccount(_client.CurrentUser.Id, true).Equals(null))
                 * {
                 *  await Utilities.Log("HandleCommandAsync",
                 *      $"Welcome the new user by the name of {_client.CurrentUser.Username}!");
                 *  var embed = new EmbedBuilder();
                 *  embed.WithTitle($"This is your first time using our bot {_client.CurrentUser.Username}!")
                 *      .WithDescription("Welcome!!")
                 *      .WithColor(new Color(Config.BotConfig.BotThemeColorR, Config.BotConfig.BotThemeColorG, Config.BotConfig.BotThemeColorB)); // Should reduce it to a color class.
                 *  await context.Channel.SendMessageAsync("", false, embed);
                 * }DF
                 */
                var result = await _service.ExecuteAsync(context, argPos, null);

                if (!result.IsSuccess && result.Error != CommandError.UnknownCommand)
                {
                    await context.Channel.SendMessageAsync(result.ErrorReason);
                }
                else
                {
                    // ------------------ create statistics machine. Class DatabaseHandler
                    // ------------------ create
                    context.Guild.GetTextChannel(GuildsData.FindGuildConfig(context.Guild.Id).LogChannelID);
                }
            }
        }
Esempio n. 5
0
        public async Task Settings([Remainder] string message)
        {
            _ = new EmbedBuilder();
            var firstWord = message.IndexOf(" ") > -1
                ? message.Substring(0, message.IndexOf(" "))
                : message;
            string      configfile = $"{GuildsData.GuildsFolder}/{Context.Guild.Id}/config.json";
            GuildConfig config     = DataStorage.RestoreObject <GuildConfig>(configfile);

            switch (firstWord)
            {
            case "View":
                await SendClassEmbed <GuildConfig>("config.json", $"Configuration for {Context.Guild.Name} :smiley:", config);

                DataStorage.StoreObject(config, configfile);
                break;

            case "Modify":
                if (Context.User.Id == Context.Guild.OwnerId || UserHasRole(config.DirectorRoleID))
                {
                    string   scan = message.Substring(message.IndexOf(" ") + 1);
                    string[] vars = scan.Split('=');
                    try
                    {
                        PropertyInfo tochange = GuildsData.FindOrCreateGuildConfig(Context.Guild).GetType().GetProperty(vars[0]);
                        if (tochange.PropertyType.IsEquivalentTo(typeof(string)))
                        {
                            tochange.SetValue(vars[1], tochange.GetValue(config, null), null);
                        }
                        else if (tochange.PropertyType.IsEquivalentTo(typeof(ulong)))
                        {
                            ulong converted;
                            try
                            {
                                converted = (UInt64)Parse <ulong>(vars[1]);
                            }
                            catch
                            {
                                await SendErrorEmbed("**Syntax error**", $"Failure to convert {vars[1]} to a long number.");

                                break;
                            }
                            tochange.SetValue(converted, tochange.GetValue(config, null), null);
                        }



                        await SendClassicEmbed("**Config.json**", $"Set {vars[0]} to {vars[1]}.");
                    }
                    catch (Exception ex)
                    {
                        await SendErrorEmbed("**Syntax error**", "Check for spaces and a proper value=this format. :smiley:");

                        await Utilities.Log(MethodBase.GetCurrentMethod(), $"Error changing GuildData. {vars[0]} = {vars[1]}", ex, LogSeverity.Error);
                    }
                }
                else
                {
                    await SendClassicEmbed("**Only an owner can use this command**", "");
                }
                break;

            case "Reset":
                if (Context.User.Id == Context.Guild.OwnerId)
                {
                    GuildsData.DeleteGuildConfig(Context.Guild.Id);
                    await SendClassicEmbed("**Success!", "To confirm, use View. :smiley:");
                }
                else
                {
                    await SendClassicEmbed("**Only an owner can use this command**", "");
                }
                break;

            default:
                await SendErrorEmbed("Syntax problem", "Choose to View, Modify, or Reset! :smiley:");

                return;
            }
        }