Exemplo n.º 1
0
 private object serializeSense(DictionarySense s)
 {
     return(new {
         glossary = s.glossary,
         misc = s.misc
     });
 }
Exemplo n.º 2
0
 public void addUserName(string key, string sense, string nameType)
 {
     lock (this) {
         Settings.app.removeBannedWord(key);
         EdictMatch        match = new EdictMatch(key);
         EdictEntryBuilder eb    = new EdictEntryBuilder();
         eb.addKanji(new DictionaryKeyBuilder(key));
         eb.addKana(new DictionaryKeyBuilder(sense));
         DictionarySense ds = new DictionarySense();
         ds.addGloss(null, sense);
         eb.addSense(ds);
         if (nameType != "notname")
         {
             eb.addPOS("name");
         }
         else
         {
             eb.addPOS("n");
         }
         eb.nameType = nameType;
         match.addEntry(new RatedEntry {
             entry = eb.build(), rate = 5.0F
         });
         userNames[key] = match;
         this.isDirty   = true;
     }
 }
Exemplo n.º 3
0
        public async Task Dictionary(string word)
        {
            string url = $"https://od-api.oxforddictionaries.com:443/api/v1/entries/en/{word.ToLower ()}";

            string json = await FetchJson(url);

            if (string.IsNullOrEmpty(json))
            {
                return;
            }
            DictionaryData data = DictionaryData.FromJson(json);

            string           finalMessage = string.Empty;
            bool             hasData      = false;
            DictionaryResult result       = data.Results [0];

            finalMessage += $"**{result.Word.ToUpper ()}**\n";

            if (result.LexicalEntries [0].Pronunciations != null)
            {
                finalMessage += $"/{result.LexicalEntries [0].Pronunciations [0].PhoneticSpelling}/\n\n";
                hasData       = true;
            }

            foreach (DictionaryLexicalEntry lexicalEntry in result.LexicalEntries ?? Enumerable.Empty <DictionaryLexicalEntry> ())
            {
                finalMessage += $"**{lexicalEntry.LexicalCategory.UppercaseFirst ()}**\n";
                foreach (DictionaryEntry entry in lexicalEntry.Entries ?? Enumerable.Empty <DictionaryEntry> ())
                {
                    for (int j = 0; j < entry.Senses.Length; j++)
                    {
                        DictionarySense sense = entry.Senses [j];
                        foreach (string definition in sense.Definitions ?? Enumerable.Empty <string> ())
                        {
                            finalMessage += $"{j + 1}. {definition.UppercaseFirst ()}\n";
                            hasData       = true;
                        }
                        foreach (DictionaryExample example in sense.Examples ?? Enumerable.Empty <DictionaryExample> ())
                        {
                            finalMessage += $"    {example.Text.UppercaseFirst ()}\n";
                            hasData       = true;
                        }
                        finalMessage += "\n";
                    }
                }
            }

            if (finalMessage.Length >= 2000 && hasData)
            {
                IEnumerable <string> messages = finalMessage.SplitEveryNth(2000);
                foreach (string message in messages)
                {
                    await ReplyAsync(message);
                }
                return;
            }
            else if (hasData)
            {
                await ReplyAsync(finalMessage);
            }
            else
            {
                await ReplyAsync($"No data found for: {word}.");
            }
        }