Ejemplo n.º 1
0
        public async Task Strawpoll(string title, params string[] options)
        {
            try
            {
                var poll = new Strawpoll();

                var obj = new PollRequest()
                {
                    Title   = title,
                    Options = new List <string>()
                    {
                        options[0], options[1]
                    },
                    Multi    = false,
                    Dupcheck = DupCheck.Normal,
                    Captcha  = false
                };

                var p = await poll.CreatePollAsync(obj);

                //var pp = await poll.GetPollAsync(p.Id);

                await ReplyAsync(p.Id.ToString());
            }
            catch (Exception ex)
            {
                await ReplyAsync("error: " + ex.Message.ToString());
            }
        }
Ejemplo n.º 2
0
        internal async Task InitializeAsync(string[] args)
        {
            if (!File.Exists("settings.json"))
            {
                var json = JsonConvert.SerializeObject(new Settings(), Formatting.Indented);
                File.WriteAllText("settings.json", json, new UTF8Encoding(false));
                Console.WriteLine("Config file was not found, a new one was generated. Fill it with proper values and rerun this program");
                Console.ReadKey();
                return;
            }

            var input = File.ReadAllText("settings.json", new UTF8Encoding(false));

            Settings = JsonConvert.DeserializeObject <Settings>(input);

            // Saving config with same values but updated fields
            var newjson = JsonConvert.SerializeObject(Settings, Formatting.Indented);

            File.WriteAllText("settings.json", newjson, new UTF8Encoding(false));

            GlobalContextBuilder = Settings.Database.CreateContextBuilder();
            PerspectiveApi       = new Perspective(Settings.PerspectiveToken);
            Strawpoll            = new Strawpoll();

            Shards = new List <ModCoreShard>();
            InitializeSharedData(args);

            // cnext data that is consistent across shards, so it's fine to share it
            for (var i = 0; i < Settings.ShardCount; i++)
            {
                var shard = new ModCoreShard(Settings, i, SharedData);
                shard.Initialize();
                Shards.Add(shard);
                if (i == 0)
                {
                    SharedData.Initialize(shard);
                }
            }

            await InitializeDatabaseAsync();

            foreach (var shard in Shards)
            {
                await shard.RunAsync();
            }

            await BuildWebHost().RunAsync(CTS.Token);

            await WaitForCancellation();

            foreach (var shard in Shards)
            {
                await shard.DisconnectAndDispose();
            }

            this.SharedData.CTS.Dispose();
            this.SharedData.TimerData.Cancel.Cancel();
            this.SharedData.TimerSempahore.Dispose();
        }
Ejemplo n.º 3
0
        public ActionResult <Strawpoll> PostStrawpoll(Strawpoll poll)
        {
            List <Answer> answers = new List <Answer>();

            poll.Answers.ToList().ForEach(e =>
            {
                Answer newAnswer = new Answer(e.AnswerString, e.AmountVoted);
                answers.Add(newAnswer);
                _answerRepository.Add(newAnswer);
            });

            Strawpoll pollDB = new Strawpoll(poll.Question, poll.DateCreated, answers);

            _strawpollRepository.Add(poll);
            _strawpollRepository.SaveChanges();

            return(CreatedAtAction(nameof(GetStrawpollById), new { id = poll.StrawpollId }, poll));
        }
Ejemplo n.º 4
0
        public ActionResult <Strawpoll> PutStrawpoll(int id, Strawpoll poll)
        {
            if (id != poll.StrawpollId)
            {
                return(BadRequest());
            }

            Strawpoll         pollDB = _strawpollRepository.GetById(id);
            IList <VotedUUID> voted  = new List <VotedUUID>();

            pollDB.DateCreated = poll.DateCreated;
            pollDB.Question    = poll.Question;
            pollDB.StrawpollId = poll.StrawpollId;

            poll.Answers.ToList().ForEach(e =>
            {
                Answer a       = _answerRepository.GetById(e.AnswerId);
                a.AmountVoted  = e.AmountVoted;
                a.AnswerString = e.AnswerString;
                _answerRepository.Update(a);
            });

            poll.AlreadyVoted.ToList().ForEach(e =>
            {
                VotedUUID a = _votedRepository.GetById(e.VotedUUIDId);
                if (a != null)
                {
                    a.UUID = e.UUID;
                    _votedRepository.Update(a);
                }
                else
                {
                    a = new VotedUUID(e.UUID);
                    _votedRepository.Add(a);
                }
                voted.Add(a);
            });

            pollDB.AlreadyVoted = voted;

            _strawpollRepository.Update(pollDB);
            _strawpollRepository.SaveChanges();
            return(CreatedAtAction(nameof(GetStrawpollById), new { id = poll.StrawpollId }, poll));
        }
Ejemplo n.º 5
0
 public void Update(Strawpoll poll)
 {
     _ctx.Strawpolls.Update(poll);
 }
Ejemplo n.º 6
0
 public void Add(Strawpoll poll)
 {
     _ctx.Add(poll);
 }
Ejemplo n.º 7
0
        static void Room_Client_MessageReceived(LiveCodingChat.Xmpp.Room room, LiveCodingChat.Xmpp.MessageReceivedEventArgs e)
        {
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine(e.Nick + ": " + e.Message);
            Console.ForegroundColor = ConsoleColor.White;

            if (!isStarted)
            {
                return;
            }
            if (e.User == null)
            {
                return;
            }
            string fnd = e.Message.ToLower();

            System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex("NE[E]*I[I]*N TO[O]*M NE[E]*I[I]*N");
            if (fnd.Contains("@tom") || fnd.Contains("@bobstriker") || r.IsMatch(fnd.ToUpper()))
            {
                if (player == null)
                {
                    System.Media.SystemSounds.Exclamation.Play();
                }
                else
                {
                    player.Play();
                }
            }

            if (e.User.ID == chatRoom.Client.Nick || e.User.ID == "octobot")//TODO email->nick/username
            {
                return;
            }
            if (fnd.Contains(chatRoom.Client.Nick) || fnd.Contains("adam"))
            {
                room.SendMessage("@" + e.Nick + ": Hier wird OctoAwesome entwickelt. Mehr Infos unter http://www.octoawesome.net");
            }
            if (e.Nick == "jvbsl" || e.User.Staff || e.User.Role == "moderator")
            {
                if (fnd.StartsWith("/strawpoll "))
                {
                    string[]  args    = e.Message.Substring("/strawpoll ".Length).Split(',');
                    Strawpoll poll    = new Strawpoll(args);
                    string    pollRes = poll.CreatePoll();
                    if (pollRes != null)
                    {
                        room.SendMessage("Neuer Poll - " + args[0] + ": " + pollRes);
                    }
                }
            }
            if (fnd.Contains("kopfoderzahl?"))
            {
                byte b = Convert.ToByte(rnd.Next(0, 2));
                switch (b)
                {
                case 0:
                    room.SendMessage("@" + e.Nick + " Kopf");
                    break;

                case 1:
                    room.SendMessage("@" + e.Nick + " Zahl");
                    break;
                }
            }
        }