Sha256: 7cd555b9c8e51ff51bbd8a2b762c9f8ac965d02da30e5da8a0de3d25f68bbe9f
Contents?: true
Size: 1.29 KB
Versions: 2
Compression:
Stored size: 1.29 KB
Contents
# frozen_string_literal: true require_relative "../models/kanal_user" module Kanal module Plugins module UserSystem module Helpers # # Serves as a storage of methods to enable automatic user creation used by UserSystem # module AutoCreator include Kanal::Plugins::UserSystem::Models # # Enables automatic creation of telegram user with telegram_chat_id property during consuming of input by router # # @param [Kanal::Core::Core] core <description> # def self.enable_telegram(core) core.hooks.attach :input_before_router do |input| tg_chat_id = input.tg_chat_id tg_chat_id_property = "telegram_chat_id" return if tg_chat_id.nil? user = KanalUser.find_all_by_property(property_name: tg_chat_id_property, property_value: tg_chat_id).first unless user username = input.tg_username username ||= "TEMP_USERNAME_#{tg_chat_id}" user = KanalUser.create(username: username) user.create_or_update_property(tg_chat_id_property, tg_chat_id) end input.user = user end end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
kanal-plugins-user_system-0.3.3 | lib/kanal/plugins/user_system/helpers/auto_creator.rb |
kanal-plugins-user_system-0.3.2 | lib/kanal/plugins/user_system/helpers/auto_creator.rb |