mirror of
				https://gitlab.com/Kwoth/nadekobot.git
				synced 2025-11-04 00:34:26 -05:00 
			
		
		
		
	add: Added .quran command, which will show the provided ayah in english and arabic, including recitation by Alafasy
This commit is contained in:
		
							
								
								
									
										102
									
								
								src/NadekoBot/Modules/Searches/ReligiousCommands.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										102
									
								
								src/NadekoBot/Modules/Searches/ReligiousCommands.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,102 @@
 | 
			
		||||
using NadekoBot.Modules.Searches.Common;
 | 
			
		||||
using System.Net.Http.Json;
 | 
			
		||||
using System.Text.Json.Serialization;
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Modules.Searches;
 | 
			
		||||
 | 
			
		||||
public partial class Searches
 | 
			
		||||
{
 | 
			
		||||
    public partial class ReligiousCommands : NadekoModule
 | 
			
		||||
    {
 | 
			
		||||
        private readonly IHttpClientFactory _httpFactory;
 | 
			
		||||
        
 | 
			
		||||
        public ReligiousCommands(IHttpClientFactory httpFactory)
 | 
			
		||||
        {
 | 
			
		||||
            _httpFactory = httpFactory;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        [Cmd]
 | 
			
		||||
        [RequireContext(ContextType.Guild)]
 | 
			
		||||
        public async Task Bible(string book, string chapterAndVerse)
 | 
			
		||||
        {
 | 
			
		||||
            var obj = new BibleVerses();
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                using var http = _httpFactory.CreateClient();
 | 
			
		||||
                obj = await http.GetFromJsonAsync<BibleVerses>($"https://bible-api.com/{book} {chapterAndVerse}");
 | 
			
		||||
            }
 | 
			
		||||
            catch
 | 
			
		||||
            {
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (obj.Error is not null || obj.Verses is null || obj.Verses.Length == 0)
 | 
			
		||||
                await Response().Error(obj.Error ?? "No verse found.").SendAsync();
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                var v = obj.Verses[0];
 | 
			
		||||
                await Response()
 | 
			
		||||
                      .Embed(_sender.CreateEmbed()
 | 
			
		||||
                                    .WithOkColor()
 | 
			
		||||
                                    .WithTitle($"{v.BookName} {v.Chapter}:{v.Verse}")
 | 
			
		||||
                                    .WithDescription(v.Text))
 | 
			
		||||
                      .SendAsync();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Cmd]
 | 
			
		||||
        [RequireContext(ContextType.Guild)]
 | 
			
		||||
        public async Task Quran(string ayah)
 | 
			
		||||
        {
 | 
			
		||||
            using var http = _httpFactory.CreateClient(); 
 | 
			
		||||
            
 | 
			
		||||
            var obj = await http.GetFromJsonAsync<QuranResponse<QuranAyah>>($"https://api.alquran.cloud/v1/ayah/{Uri.EscapeDataString(ayah)}/editions/en.asad,ar.alafasy");
 | 
			
		||||
            if(obj is null or not { Code: 200 })
 | 
			
		||||
            {
 | 
			
		||||
                await Response().Error("No verse found.").SendAsync();
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var english = obj.Data[0];
 | 
			
		||||
            var arabic = obj.Data[1];
 | 
			
		||||
 | 
			
		||||
            await using var audio = await http.GetStreamAsync(arabic.Audio);
 | 
			
		||||
 | 
			
		||||
            await Response()
 | 
			
		||||
                  .Embed(_sender.CreateEmbed()
 | 
			
		||||
                                .WithOkColor()
 | 
			
		||||
                                .AddField("Arabic", arabic.Text)
 | 
			
		||||
                                .AddField("English", english.Text)
 | 
			
		||||
                                .WithFooter(arabic.Number.ToString()))
 | 
			
		||||
                  .File(audio, Uri.EscapeDataString(ayah) + ".mp3")
 | 
			
		||||
                  .SendAsync();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public sealed class QuranResponse<T>
 | 
			
		||||
{
 | 
			
		||||
    [JsonPropertyName("code")]
 | 
			
		||||
    public int Code { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [JsonPropertyName("status")]
 | 
			
		||||
    public string Status { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [JsonPropertyName("data")]
 | 
			
		||||
    public T[] Data { get; set; }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public sealed class QuranAyah
 | 
			
		||||
{
 | 
			
		||||
    [JsonPropertyName("number")]
 | 
			
		||||
    public int Number { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [JsonPropertyName("audio")]
 | 
			
		||||
    public string Audio { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [JsonPropertyName("name")]
 | 
			
		||||
    public string Name { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [JsonPropertyName("text")]
 | 
			
		||||
    public string Text { get; set; }
 | 
			
		||||
    
 | 
			
		||||
}
 | 
			
		||||
@@ -528,34 +528,6 @@ public partial class Searches : NadekoModule<SearchesService>
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [Cmd]
 | 
			
		||||
    [RequireContext(ContextType.Guild)]
 | 
			
		||||
    public async Task Bible(string book, string chapterAndVerse)
 | 
			
		||||
    {
 | 
			
		||||
        var obj = new BibleVerses();
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            using var http = _httpFactory.CreateClient();
 | 
			
		||||
            obj = await http.GetFromJsonAsync<BibleVerses>($"https://bible-api.com/{book} {chapterAndVerse}");
 | 
			
		||||
        }
 | 
			
		||||
        catch
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (obj.Error is not null || obj.Verses is null || obj.Verses.Length == 0)
 | 
			
		||||
            await Response().Error(obj.Error ?? "No verse found.").SendAsync();
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            var v = obj.Verses[0];
 | 
			
		||||
            await Response()
 | 
			
		||||
                  .Embed(_sender.CreateEmbed()
 | 
			
		||||
                         .WithOkColor()
 | 
			
		||||
                         .WithTitle($"{v.BookName} {v.Chapter}:{v.Verse}")
 | 
			
		||||
                         .WithDescription(v.Text))
 | 
			
		||||
                  .SendAsync();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [Cmd]
 | 
			
		||||
    public async Task Steam([Leftover] string query)
 | 
			
		||||
    {
 | 
			
		||||
 
 | 
			
		||||
@@ -1192,6 +1192,8 @@ xpreset:
 | 
			
		||||
  - xpreset
 | 
			
		||||
bible:
 | 
			
		||||
  - bible
 | 
			
		||||
quran:
 | 
			
		||||
  - quran
 | 
			
		||||
edit:
 | 
			
		||||
  - edit
 | 
			
		||||
delete:
 | 
			
		||||
 
 | 
			
		||||
@@ -4076,6 +4076,16 @@ bible:
 | 
			
		||||
        desc: "The name of the biblical book being referenced."
 | 
			
		||||
      chapterAndVerse:
 | 
			
		||||
        desc: "The reference to a specific passage in the Bible, such as 'Genesis 3:15'"
 | 
			
		||||
quran:
 | 
			
		||||
  desc: |-
 | 
			
		||||
    Shows the text of an ayah of the Quran, as well as the recitation by Alafasy.
 | 
			
		||||
    Supply surah:ayah, or ayah number. For instance, 262 or 2:255 will both get you Ayat Al Kursi
 | 
			
		||||
  ex:
 | 
			
		||||
    - 2:255
 | 
			
		||||
    - 262
 | 
			
		||||
  params:
 | 
			
		||||
    - ayah:
 | 
			
		||||
        desc: "The number of the ayah in the Quran, for example 2:255."
 | 
			
		||||
edit:
 | 
			
		||||
  desc: Edits bot's message, you have to specify message ID and new text. You can optionally specify target channel. Supports embeds.
 | 
			
		||||
  ex:
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user