예제 #1
0
        async Task IIb3Command.Run(IIb3Bot callingBot, DiscordClient client, DiscordUser user, DiscordChannel channel, string[] args)
        {
            bool   ShouldShowUsage = false;
            bool   Found           = false;
            string ExplicitCommand = null;

            if (args.Length >= 1)
            {
                ShouldShowUsage = true;
                ExplicitCommand = args[0];
            }

            DiscordEmbedBuilder builder = new DiscordEmbedBuilder
            {
                Title       = "co80bot help",
                Description = "Help on your favorite, ~~shoddily coded~~ bot",
                Color       = new DiscordColor(0xFF9900)
            };


            if (ExplicitCommand != null && ShouldShowUsage)
            {
                builder.Title = $"co80bot help - lookup {ExplicitCommand}";
                // explicit command to look up
                // also prints usage for this specific command
                foreach (IIb3Command command in DiscordBot.commands)
                {
                    if (command.Name == ExplicitCommand)
                    {
                        Found = true;
                        builder.AddField(command.Name, $"Description:\n{command.Description}\nUsage:\n```\n{ ((DiscordBot)callingBot).Prefix }{ command.Name } { command.HelpDescription}\n```", true);
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }

                // If we somehow got past here and the command wasn't found: ?Que?
                if (!Found)
                {
                    builder.AddField("Error!", "Your specified command couldn't be found!", true);
                }
            }
            else
            {
                // small list of every command
                foreach (IIb3Command command in DiscordBot.commands)
                {
                    builder.AddField(command.Name, command.Description, true);
                }
            }

            await client.SendMessageAsync(channel, null, false, builder.Build());
        }
예제 #2
0
파일: Program.cs 프로젝트: modeco80/co80bot
        static async Task <int> Main(string[] args)
        {
            Console.WriteLine("IronBot3 API Runner - The magic that powers IronBot 3/co80bot!");
            Console.WriteLine("(C) 2019 Modeco80 <3");

            if (args.Length == 1)
            {
                if (args[0].ToLower() == "--help")
                {
                    Console.WriteLine("API Runner Usage: " + AppDomain.CurrentDomain.FriendlyName + " [Bot dll name]");
                    Console.WriteLine($"If no arguments are passed, the API Runner will use {Program.DEFAULT_IB3_BOT}.");
                    return(0);
                }



                // User defined bot assembly
                await Logger.Log($"Using user-defined assembly \"{args[0]}\".");

                BotAssemblyPath = args[0];
            }
            else
            {
                // Use the default co80bot
                await Logger.Log($"Using assembly \"{Program.DEFAULT_IB3_BOT}\".");

                BotAssemblyPath = Program.DEFAULT_IB3_BOT;
            }

            // Initalize bot
            IIb3Bot bot = LoadBot(BotAssemblyPath);

            if (bot == null)
            {
                await Logger.Log("Error loading bot, exiting.", Logger.Severity.Warning);

                return(1);
            }

            await Logger.Log($"Starting bot \"{BotAssemblyPath}\".");

            await bot.Start();

            return(0);
        }
예제 #3
0
파일: Program.cs 프로젝트: modeco80/co80bot
        public static IIb3Bot LoadBot(string BotAssemPath)
        {
            Assembly BotAssembly;
            IIb3Bot  bot = null;

            try
            {
                BotAssembly = Assembly.LoadFrom(BotAssemPath);
            }
            catch (Exception ex)
            {
                Logger.Log($"Error loading bot {BotAssemPath}", Logger.Severity.Error);
                Logger.Log($"Exception message: {ex.Message}", Logger.Severity.Error);
                return(null);
            }

            foreach (Type AssemblyType in BotAssembly.GetTypes())
            {
                if (typeof(IIb3Bot).GetTypeInfo().IsAssignableFrom(AssemblyType.GetTypeInfo()))
                {
                    object BotInstance = Activator.CreateInstance(AssemblyType);
                    try
                    {
                        bot = (IIb3Bot)BotInstance;
                        Logger.Log($"Bot assembly \"{BotAssemPath}\" loaded successfully.");
                    }
                    catch (Exception ex)
                    {
                        Logger.Log($"Error loading bot {BotAssemPath}", Logger.Severity.Error);
                        Logger.Log($"Exception message: {ex.Message}", Logger.Severity.Error);
                        return(null);
                    }
                    return(bot);
                }
            }

            // Return a nullref if there is an error.
            return(null);
        }