Exemplo n.º 1
0
        public void Install(ModuleManager manager)
        {
            _client = manager.Client;

            _client.UserJoined += async (s, e) => 
            {
                var buffer = string.Format("Welcome to '{0}', {1}\n\n", e.Server, Mention.User(e.User));
                buffer += _client.Commands().AllCommands.ToDiscordMessage();
                await _client.SendPrivateMessage(e.User, buffer);
                await _client.SendMessage(e.Server.DefaultChannel, string.Format("A wild {0} appears!", Mention.User(e.User)));
            };

            _client.UserLeft += async (s, e) => 
            {
                await _client.SendMessage(e.Server.DefaultChannel, string.Format("See you soon, {0}!", Mention.User(e.User)));
            };

            _client.ChannelUpdated += async (s, e) => 
            {
                if (_botServices.Server.ChannelTopicUpdated(e.Channel))
                {
                    await _client.SendMessage(e.Channel, string.Format("**Topic Updated**\n'{0}'", e.Channel.Topic));
                }
            };

            /*_client.UserPresenceUpdated += async (s, e) => 
            {
                if (_botServices.Server.UserHasReturned(e.Server, e.User))
                {
                    //await _client.SendMessage(e.Server.DefaultChannel, string.Format("Welcome back, {0}!", Mention.User(e.User)));
                }
            };*/

            _client.ChannelCreated += async (sender, e) =>
            {
                await _client.SendMessage(e.Server.DefaultChannel, string.Format("**New Channel Created**\n{0}", Mention.Channel(e.Channel)));
            };

            _client.MessageReceived += async (s, e) =>
            { 
                if (e.Message.IsAuthor)
                    return;

                var reply = _botServices.AI.GetReply(e.Message.Channel, e.Message);
                if(!string.IsNullOrEmpty(reply))
                {
                    await _client.SendMessage(e.Message.Channel, reply);
                }
            };

            _botServices.Ticker.OnTicked += async (s, e) => 
            {
                if (_botServices.Ticker.TicksElapsed(e.Ticks, 240))
                { 
                    await Announce(e);
                }
            };
        }
Exemplo n.º 2
0
        void IModule.Install(ModuleManager manager)
        {
            _manager = manager;
            _client = manager.Client;
            InitializeDeck();
            ImportListenList();
            ImportCards();

            manager.CreateCommands("Flip", group =>
            {
                group.CreateCommand("")
                .Description("Flip a coin")
                .Do(async e =>
                {
                    Random rand = new Random();
                    int flip = rand.Next(1, 3);
                    string side = "";
                    if (flip == 1)
                        side = "Heads";
                    else side = "Tails";
                    Message m = await _client.SendMessage(e.Channel, "Flipping a coin...");
                    System.Threading.Thread.Sleep(1500);
                    await _client.EditMessage(m, "The coin spins high into the air!");
                    System.Threading.Thread.Sleep(1500);
                    await _client.EditMessage(m, $"The coin lands... and it's {side}!");
                });
            });

            manager.CreateCommands("Roll", group =>
            {
                group.CreateCommand("Listen")
                .Description("Asks Rollbot to listen to the channel for rolls")
                .Do(async e =>
                {
                    ListenToChannel(e.Channel);
                    if (!_channelsToListenTo.Contains(e.Channel))
                    {

                        _channelsToListenTo.Add(e.Channel);
                        await _client.SendMessage(e.Channel, "Now listening for rolls in here");
                    }
                    else
                        await _client.SendMessage(e.Channel, "Already listening in here");
                });

                group.CreateCommand("Ignore")
                .Description("Asks Rollbot to stop listening to the channel for rolls")
                .Do(async e =>
                {
                    IgnoreChannel(e.Channel);
                    if (_channelsToListenTo.Contains(e.Channel))
                    {
                        _channelsToListenTo.Remove(e.Channel);
                        await _client.SendMessage(e.Channel, "No longer listening for rolls here");
                    }
                    else
                        await _client.SendMessage(e.Channel, "Wasn't listening anyways, haha");

                });

                group.CreateCommand("")
                .Description("Asks for a roll, even if rollbot isn't listening.")
                .Parameter("What you'd like to roll.")
                .Do(async e =>
                {
                    if (e.Args == null)
                    {
                        await _client.SendMessage(e.Channel, "No roll provided");
                        return;
                    }
                    string message = e.Args[0];
                    GetRoll(_client, e, message);
                });
            });

            manager.CreateCommands("Cards", group =>
            {
                group.CreateCommand("")
                .Description("Provides info on cards")
                .Do(async e =>
                {
                    await _client.SendPrivateMessage(e.User, "To draw a card, use !cards draw. To reset the deck, say !cards reset");
                });

                group.CreateCommand("Reset") //Assumes 0 Jokers.
                .Description("Resets the deck.")
                .Do(async e =>
                {
                    InitializeDeck(0, e.Channel);
                    await _client.SendMessage(e.Channel, $"Resetting the deck with no jokers.");
                    SaveDeck(e.Channel);
                });

                group.CreateCommand("Reset") //Takes a parameter.
                .Description("Resets the deck with a number of jokers.")
                .Parameter("Number of jokers to include, if any.")
                .Do(async e =>
                {
                    try
                    {
                        int jokers = 0;
                        jokers = int.Parse(e.Args[0]);
                        if (jokers < 0)
                            jokers = 0;
                        InitializeDeck(jokers, e.Channel);
                        await _client.SendMessage(e.Channel, $"Resetting the deck with {jokers} jokers.");
                        SaveDeck(e.Channel);
                    }
                    catch (FormatException ex)
                    {
                        await _client.SendMessage(e.Channel, "Please provide a number of jokers." +ex.Message);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Failed to reload deck. " + ex.Message);
                    }
                });

                group.CreateCommand("New")
                .Description("Clears the old deck and starts a new user-defined deck.")
                .Parameter("Comma seperated list of suits", ParameterType.Required)
                .Parameter("Comma seperated list of values", ParameterType.Required)
                .Parameter("Comma seperated list of cards.", ParameterType.Unparsed)
                .MinPermissions((int) PermissionLevel.ServerMod)
                .Do(async e =>
                {
                    EnsureDeckExists(e.Channel);
                    _cards[e.Channel].Clear();
                    if(e.Args.Length >= 3)
                    {
                        string[] miscCards = e.Args[2].Split(',');
                        _cards[e.Channel].AddRange(miscCards);
                    }
                    //We have a value for "suits" and "Values"
                    string[] suits = e.Args[0].Split(',');
                    string[] values = e.Args[1].Split(',');
                    foreach (string s1 in suits)
                    {
                        foreach (string s2 in values)
                        {
                            _cards[e.Channel].Add($"{s2} of {s1}");
                        }
                    }
                    await _client.SendMessage(e.Channel, "New deck imported successfully.");
                    SaveDeck(e.Channel);
                });

                group.CreateCommand("New Nosuits")
                .Description("Clears the old deck and makes a new one composed of only specified cards.")
                .Parameter("Comma seperated list of cards.")
                .Do(async e =>
                {
                    EnsureDeckExists(e.Channel);
                    _cards[e.Channel].Clear();
                    _cards[e.Channel] = e.Args[0].Split(',').ToList();
                    await _client.SendMessage(e.Channel, "New deck imported successfully.");
                    SaveDeck(e.Channel);
                });

                group.CreateCommand("Draw")
                .Description("Draws a card from the current deck.")
                .Do(async e =>
                {
                    await _client.SendMessage(e.Channel, DrawCard(e.Channel));
                    SaveDeck(e.Channel);
                });

                group.CreateCommand("PDraw")
                .Description("Draws a card privately")
                .Do(async e =>
                {
                    await _client.SendPrivateMessage(e.User, DrawCard(e.Channel));
                    SaveDeck(e.Channel);
                });

                group.CreateCommand("List")
                .Description("Reveals the entire deck")
                .MinPermissions((int) PermissionLevel.ServerMod)
                .Do(async e =>
                {
                    EnsureDeckExists(e.Channel);
                    string cards = "";
                    foreach (string s in _cards[e.Channel])
                    {
                        cards += $"{s}, ";
                    }
                    if (cards.Length >= 2)
                    {
                        cards = cards.Remove(cards.Length - 2);
                    }
                    else
                        cards = "Nothing";
                    await _client.SendMessage(e.Channel, $"Deck currently contains: {cards}");
                });
            }); 

            _client.MessageReceived += (s, e) =>
            {
                if (e.User.Id != _client.CurrentUser.Id && _channelsToListenTo.Contains(e.Channel))
                {
                    string message = e.Message.Text;
                    GetRoll(_client,e, message);
                }
            };
            
        }