private static BotCommandManager SetUpCommands() { var cmdMgr = new BotCommandManager(); using var stream = System.IO.File.OpenRead("./Commands.json"); cmdMgr.Load(stream).Wait(); return(cmdMgr); }
public PivasBotService(string botToken, string dbConnectionString = null) { DbConnection dbConn = new DbConnection(dbConnectionString); _botClient = new TelegramBotClient(botToken); _messageService = new MessageService(dbConn); _jokeService = new JokeService(dbConn); _commandManager = new BotCommandManager(_botClient, _messageService, _jokeService); _conversationStats = new ConversationStats(); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddRazorPages(); services.AddServerSideBlazor(); // Create the storage we'll be using for User and Conversation state. (Memory is great for testing purposes.) services.AddSingleton <IStorage, MemoryStorage>(); // Create the User state. services.AddSingleton <UserState>(); BotCommandManager cmdMgr = SetUpCommands(); services.AddSingleton <BotCommandManager>(cmdMgr); services.AddSingleton <CommandTypeManager>(); services.AddTransient <IBot, SampleTwitchBot>(); var twitchSettings = new TwitchAdapterSettings(); Configuration.GetSection("twitchBot").Bind(twitchSettings); services.AddTwitchBotAdapter(twitchSettings); }
public MainWindow() { _commandManager = new BotCommandManager(); bool.TryParse(ConfigurationManager.AppSettings["testmode"], out _testMode); _username = ConfigurationManager.AppSettings["username"]; string password = ConfigurationManager.AppSettings["oauth"]; string channel = ConfigurationManager.AppSettings["channel"]; if (_testMode) { _irc = new IrcClient(); } else { _irc = new IrcClient("irc.twitch.tv", 6667, _username, password); //password from www.twitchapps.com/tmi } //join channel _irc.JoinRoom(channel); //Add commands _commandManager.AddCommand("!hype", "Used to generate hype!", (message) => { string returnMessage = "HYPE HYPE HYPE!!!!"; _irc.SendChatMessage(returnMessage); UpdateChatDisplay(new Message(_irc.GenerateChatMessage(_username, returnMessage)), Colors.Blue, Colors.White); }); _commandManager.AddCommand("!name", "Used to generate a random name. Give a username afterwards to assign it to someone.", (message) => { Regex r = new Regex(@"!name @[\w_\-]+"); NameGenerator ng = new NameGenerator(); string returnMessage = null; if (r.IsMatch(message)) { string u = message.Substring(7); returnMessage = u + "'s new name is " + ng.GetName(); } else { returnMessage = ng.GetName(); } _irc.SendChatMessage(returnMessage); UpdateChatDisplay(new Message(_irc.GenerateChatMessage(_username, returnMessage)), Colors.Blue, Colors.White); }); _commandManager.AddCommand("!source", "Gets a link to the source code!", (message) => { string returnMessage = @"https://github.com/AronDavis/TwitchBot"; _irc.SendChatMessage(returnMessage); UpdateChatDisplay(new Message(_irc.GenerateChatMessage(_username, returnMessage)), Colors.Blue, Colors.White); }); InitializeComponent(); }
public SampleTwitchBot(UserState userState, BotCommandManager cmdMgr) { _userState = userState; _commands = cmdMgr.Commands; }