GithubHelp home page GithubHelp logo

akita_neru's Introduction

What is Akita Neru

Akita Neru is an extensible Discord application framework written in TypeScript focusing on customisiability and ease of use, developers of any level should be able to create applications with the framework.

Akita Neru (亞北ネル) a.k.a. "Got bored. Going to bed." is one of the core principles of the framework, we keep you from having to write the boring command managers and event managers while also giving you the control of the wheel.

akita_neru's People

Contributors

wizardlink avatar

Watchers

 avatar  avatar

akita_neru's Issues

Create an i18n manager

A much requested feature for kanna was i18n, this will be implemented within our framework so any of our applications (and those who use the framework) are able to have it also out of the box.

This manager has to extend the BaseManager so it can load up all the translation files.

Configuration

A new field has to be added to the IConfig interface for configuring the i18n manager.

interface IConfig
{
  ...,
  i18n: {
    defaultLanguage?: LanguageTag,
  }
}

Features

  1. Automatically load & use i18n translation files.
  2. Ability to refresh manager (forcing a re-load of all files)
    • This can be used as reference.
  3. Accessible anywhere through AkitaNeru via <AkitaNeru>.i18n.

The class should therefore be called I18nManager and have a public property resources, of type Map<string, ITranslationFile>, as well as a method <I18nManager>.find(resource: string, tag: LanguageTag): string that returns the translated resource or the default resource if it is not yet translated, if both aren't found, silently throw an error.

Files

Translation files should be JSONs and are to follow this interface:

interface ITranslationFile
{
  language?: LanguageTag // The language this file translates, i.e. English.
  messages?: { [key: string]: string | string[] } // The translations itself.
}

Language tag references

// Reference - http://www.i18nguy.com/unicode/language-identifiers.html
enum LanguageTag
{
  ABKHAZIAN = 'zb',
  AFRIKAANS = 'af',
  AKAN = 'ak',
  ALBANIAN = 'sq',
  AMHARIC = 'am',
  ARABIC = 'ar-SA',
  ARAGONESE = 'an',
  ARMENIA = 'hy',
  ASSAMESE = 'as',
  AVARIC = 'av',
  AVESTAN = 'ae',
  AYMARA = 'ay',
  AZERBAIJANI = 'az',
  BAMBARA = 'bm',
  BASQUE = 'eu',
  BELARUSIAN = 'be',
  BIHARI = 'bh',
  BOKMAL = 'nb',
  BOSNIAN = 'bs',
  BRETON = 'br',
  BULGARIAN = 'bg',
  BURMESE = 'my',
  CATALAN = 'ca',
  CHICHEWA = 'ny',
  CHINESE = 'zh-CN',
  CHURCH_SLAVIC = 'cu',
  CORNISH = 'kw',
  CORSICAN = 'co',
  CREE = 'cr',
  CROATIAN = 'hr-HR',
  CZECH = 'cs',
  DINKA = 'din',
  DIVEHI = 'dv',
  DZONGKHA = 'dz',
  ENGLISH = 'en-US',
  ESPERANTO = 'eo',
  ESTONIAN = 'et',
  EWE = 'ee',
  FAROESE = 'fo',
  FIJIAN = 'fj',
  FRENCH = 'fr-FR',
  GAELIC = 'gd',
  GALICIAN = 'gl',
  GANDA = 'lg',
  GEORGIAN = 'ka',
  GERMANY = 'de-DE',
  GILBERTESE = 'gil',
  GREEK = 'el-GR',
  GUARANI = 'gn',
  GUJARATI = 'gu',
  HAITIAN = 'ht',
  HAKKA = 'i-hak',
  HAUSA = 'ha',
  HAWAIIAN = 'haw',
  HEBREW = 'he',
  HERERO = 'hz',
  HINDI = 'hi',
  HIRI_MOTU = 'ho',
  HUNGARIAN = 'hu-HU',
  ICELANDIC = 'is',
  IDO = 'io',
  IGBO = 'ig',
  INARI_SAMI = 'smn',
  INDONESIAN = 'id',
  INTERLINGUA = 'ia',
  INTERLINGUE = 'ie',
  INUKTITUT = 'iu',
  INUPIAQ = 'ik',
  ITALIAN = 'it-IT',
  JAPANESE = 'ja',
  JAVANESE = 'jv',
  KANNADA = 'kn',
  KANURI = 'kr',
  KASHMIRI = 'ks',
  KAZAKH = 'kk',
  KHMER = 'km',
  KIKUYU = 'ki',
  KIRGHIZ = 'ky',
  KONGO = 'kg',
  KONKANI = 'kok',
  KOREAN = 'ko-KP',
  KURDISH = 'ku',
  LAO = 'lo',
  LATIN = 'la',
  LATVIAN = 'lv',
  LITHUANIAN = 'lt',
  LUXEMBOURGISH = 'lb',
  MALAGASY = 'mg',
  MALAY = 'ms-MY',
  MALAYALAM = 'ml',
  MANX = 'gv',
  MAORI = 'mi',
  MARATHI = 'mr',
  MARSHALLESE = 'mh',
  MOLDAVIAN = 'mo',
  MONGOLIAN = 'mn',
  NAURU = 'na',
  NAVAJO = 'nv',
  NDONGA = 'ng',
  NEPALI = 'ne',
  NORWEGIAN = 'no',
  NYNORSK = 'nn',
  OCCITAN = 'oc',
  OJIBWA = 'oj',
  ORIYA = 'or',
  OSSETIAN = 'os',
  PALI = 'pi',
  PANJABI = 'pa',
  POLISH = 'pl',
  PORTUGUESE = 'pt-PT',
  PORTUGUESE_BRAZIL = 'pt-BR',
  PUSHTO = 'ps',
  QUECHUA = 'qu',
  RAETO_ROMANCE = 'rm',
  ROMANIAN = 'ro',
  RUNDI = 'rn',
  RUSSIAN = 'ru-RU',
  SAMI = 'se',
  SAMOAN = 'sm',
  SANKSRIT = 'sa',
  SARDINIAN = 'sc',
  SERBIAN = 'sr',
  SHONA = 'sn',
  SICHUAN_YI = 'ii',
  SIDAMO = 'sid',
  SINHALA = 'si',
  SLOVAK = 'sk',
  SORBIAN = 'wen',
  SOTHO = 'st',
  SUNDANESE = 'su',
  SWAHILI = 'sw-TZ',
  SWATI = 'ss-SZ',
  SWEDISH = 'sv-SE',
  SYRIAC = 'syr',
  TAGALOG = 'tl',
  TAHITIAN = 'ty',
  TAJIK = 'tg',
  TATAR = 'tt',
  TELUGU = 'te',
  THAI = 'th',
  TIBETAN = 'bo',
  TONGAN = 'to',
  TSONGA = 'ts',
  TURKISH = 'tr-TR',
  TUVALU = 'tvl',
  TWI = 'tw',
  UIGHUR = 'ug',
  UKRAINIAN = 'uk',
  UZBEK = 'uz-UZ',
  VENDA = 've',
  VOLAPUUK = 'vo',
  WALAMO = 'wal',
  WALLOON = 'wa',
  WOLOF = 'wo',
  XHOSA = 'xh',
  YIDDISH = 'yi',
  YORUBA = 'yo',
  YUE = 'zh-yue',
  ZHUANG = 'za',
  ZULU = 'zu',
  KUANYAMA = 'kj',
}

Create a resolver/command parser structure

A similar structure to the Resolver done for kanna has to be re-created to more easily maintain the parsing of text within Akita. The purpose of it is only to resolve text into meaningful data, such as resolving a member from a piece of text.

Features

  1. Parsing message content for relevant information.
    • The relevant information in question is the content with the prefix stripped from it (if necessary [see item below]), split into an array, removing all whitespace characters.
    • Must have an optional argument for whether it should check if a prefix is being used. When checking such, remember to develop having in mind that prefixes can be followed by spaces and then the command name.
  2. Resolve from input string users, members, channels, roles and custom emojis.

Kanna's Resolver can be used for reference when working in the second feature, for the first one, this can be used, reminding that this has to be removed from the CommandManager.

This class has to be instanced within the Client class and be a publicly accessible property of it, since, this is relevant within commands but also events.

Implement BaseCommand features

ICommandOptions has the following properties which aren't being used:

  1. Aliases
    • Commands are invoked just using their names. Needs to be implemented here so it can be invoked like this <AkitaNeru>.client.commands.find(name, type). See CommandType.
  2. Cooldown
    • Currently commands can be spammed, this will prevent that to happen. Down the line, a smart system has to be implemented to avoid people from purposefully spamming them.
  3. Permissions
    • This is to quickly limit a command to specific permissions, such as limiting a ban command to members with MANAGE_SERVER only.

A new property must be added too: channelType?, this indicating whether it is a command limited to DMs or guilds only, this can be either implemented by creating an enumerator.

This property has to be optional since by default, the framework allows commands to be only ran on guilds, however, that can be lifted by passing this to the config:

{ commands: { allowDM: true } }

Create a logger manager

A logger manager is to be created following the specifications below, keep in mind that this should be instanced right after the ConfigManager since practically everything depends on it.

Configuration

interface IConfig
{
  ...,
  logger: {
    disabled?: boolean          // Whether logging should be disabled entirely.
    all?: boolean               // Whether to log everything or not, if disabled, non-important logs will be omitted.
    bootup?: boolean            // Whether to log client startup, shutdown, etc. or not. Will include sharding, when implemented.
    loading?: boolean           // ... log loading 'events' or not, such as commands and events loading.
    sentry?: ConstructorOptions // Configuration for sentry.io using raven, if omitted, a file will be generated instead.
  }
}

Note about <IConfig>.logger.all
This is a configuration that will enable all the other options below of it, however, this also will enable debug logs across the board, including typeorm's and discord.js's debug logs.

Colors

chalk can be used for this and is encouraged.

This enumerator should be followed for colors:

enum LogColor
{
  ERROR = '\x1b[31m',    // If using chalk: 225,0,45 | #e1002d
  DEBUG = '\x1b[32m',    // ... chalk: 64,255,0 | #40ff00
  INFO = '\x1b[34m',     // ... chalk: 72,143,246 | #488ff6
  WARNING = '\x1b[33m',  // ... chalk: 255,255,51 | #ffff33
  EMPHASIS = '\x1b[35m', // ... chalk: 191,0,255 | #bf00ff
}

If chalk isn't being used, a bg<Name> property needs to be added to each one, otherwise, use the same color. Text should generally always be white, but, when emphasis is needed you can use the <LogColor>.EMPHASIS color.

NOTE - If there are readability issues with any of these colors, please comment over them and we'll arrange a new color.

Features

  1. Access colors
    • Colors should be accessed via their names, like <LoggerManager>.info(message: string, isBackground?: boolean).
  2. Logging (obviously)
    • This should be either accessed via <LoggerManager>.log(message: string, options: ILogOptions).
    • An example of a log message is: <LoggerManager>.log(<LoggerManager>.info('[' + <LoggerManager>.emphasis('READY') + ']', true) + ' Client is ready!')
  3. Decorator
    • A decorator should be made that in it's nature, will catch any errors created by the method and log it as well register it (file or sentry.io).

Logging options (ILogOptions)

// These are basically template references for more easily log messages
enum ILogType
{
  ERROR = 'error',      // [ERROR] → <Message>
  DEBUG = 'debug',      // [DEBUG] → <Message>
  INFO = 'info',        // [INFO] → <Message>
  WARNING = 'warning',  // [WARNING] → <Message>
}

interface ILogOptions
{
  type?: ILogType    // The logging template, optional
  register?: boolean // Whether to report to sentry or on a file
  silent?: boolean // Only report, don't log to console
}

Errors

When an error is caught with the decorator, it should send to sentry.io if it's configured, or, create a directory (if it doesn't exists) inside <ConfigManager>.rootDirectory called .log and then a file akita_neru.error_<time>.log. An example name for the file is: akita_neru.error_2021-06-24.log.

CommandManager improvements

Currently the command manager has only three distinct features: The ability to find managed commands (<CommandManager>.find(name, type)), to parse a message's content to handle it's prefix and arguments (<CommandManager>.parseMessage(content)) and to update (set, patch, delete) interactions loaded (<CommandManager>.setInteractions()).

Known problems

  • ...find(name, type)
    • Lacks the usage of aliases, should be resolved when #1 is closed.
  • ...parseMessage(content)
    • Does not allows for prefixes which are followed by spaces (i.e. kanna ping). This should be fixed with #4.
  • ...setInteractions()
    • Doesn't updates commands if they're different. Current problem is that if a slash command is edited it will resolve in an error and never trigger an interaction event.
  • Within IConfig you can see that the command manager has the option to be disabled, however, this is currently not handled whatsoever, this has to be fixed.

Needed improvements

Currently the command handling is being done entirely within the files which handle the interaction and message client events, found here. A method has to be created inside the command manager to be called for command handling instead of maintaining them in two distinct files.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.