public virtual void PlayerLeave(MatrixUser user)
        {
            int before = users.Count;

            users.RemoveAll(x => x.UserID == user.UserID);
            if (users.Count == 0)
            {
                this.Dispose();
            }
            if (GameInSession && before != users.Count)
            {
                room.SendMessage("The game was abandoned by " + user.DisplayName);
                this.Dispose();
            }
        }
Exemple #2
0
        public static void PlaylistDisplay(string cmd, string sender, MatrixRoom room)
        {
            string[] files  = Program.MPCClient.Playlist();
            string   output = "▶ ";

            if (files.Length > 0)
            {
                for (int i = 0; i < files.Length; i++)
                {
                    if (i > 4)
                    {
                        break;
                    }
                    string file = files [i].Substring(0, files [i].Length - 4) + '\n';                     //Remove the extension
                    file    = new string(System.Text.Encoding.UTF8.GetChars(Convert.FromBase64String(file)));
                    output += file + "\n";
                }

                room.SendMessage(output);
            }
            else
            {
                room.SendNotice("The playlist is empty");
            }
        }
 public Lobby(MatrixRoom Room, MatrixUser Owner, MatrixClient Client)
 {
     room   = Room;
     owner  = Owner;
     client = Client;
     room.SendMessage("You've created a new lobby, the game will commence once the owner has said 'START'");
     room.OnEvent += Room_OnEvent;
     users         = new List <MatrixUser>();
 }
        public static void TestCards(string cmd, string sender, MatrixRoom room)
        {
            List <PlayingCard> deck = PlayingCard.GetStandardDeck();

            PlayingCard.ShuffleDeck(ref deck);
            string             cards   = PlayingCard.GetDeckHTML(deck);
            MMessageCustomHTML htmlmsg = new MMessageCustomHTML();

            htmlmsg.formatted_body = cards;
            htmlmsg.body           = string.Join <PlayingCard>(" ", deck);
            room.SendMessage(htmlmsg);
        }
        public static void Help(string cmd, string sender, MatrixRoom room)
        {
            string helptext = "";

            foreach (MethodInfo method in typeof(Commands).GetMethods(BindingFlags.Static | BindingFlags.Public))
            {
                BotCmd  c = method.GetCustomAttribute <BotCmd> ();
                BotHelp h = method.GetCustomAttribute <BotHelp> ();
                if (c != null)
                {
                    helptext += String.Format("<p><strong>{0}</strong> {1}</p>", c.CMD, h != null ? h.HelpText : "");
                }
            }
            MMessageCustomHTML htmlmsg = new MMessageCustomHTML();

            htmlmsg.body           = helptext.Replace("<strong>", "").Replace("</strong>", "").Replace("<p>", "").Replace("</p>", "\n");
            htmlmsg.formatted_body = helptext;
            room.SendMessage(htmlmsg);
        }
Exemple #6
0
        static void Room_OnMessage(MatrixRoom room, MatrixSDK.Structures.MatrixEvent evt)
        {
            if (evt.age > 3000)
            {
                return;                 // Too old
            }

            string msg = ((MatrixMRoomMessage)evt.content).body;

            if (msg.StartsWith("!cardbot"))
            {
                msg = msg.Substring(9);
                string[] parts = msg.Split(' ');
                string   cmd   = parts [0].ToLower();
                try
                {
                    MethodInfo method = Cmds.First(x => {
                        return((x.Key.CMD == cmd) || (x.Key.BeginsWith.Any(y => cmd.StartsWith(y))));
                    }).Value;

                    Task task = new Task(() => {
                        method.Invoke(null, new object[3] {
                            msg, evt.sender, room
                        });
                    });
                    task.Start();
                }
                catch (InvalidOperationException) {
                    //Command not found
                }
                catch (Exception e) {
                    Console.Error.WriteLine("Problem with one of the commands");
                    Console.Error.WriteLine(e);
                }
            }
            else if (msg == "botsnack")
            {
                room.SendMessage("Nom nom nom");
            }
        }
 public static void Ping(string cmd, string sender, MatrixRoom room)
 {
     room.SendMessage("Pong: " + DateTime.Now.ToShortTimeString());
 }