Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement time and fix bugs #5

Open
wants to merge 6 commits into
base: config_impl
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Assets/GuiTreeArrowDown.svg.import
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
Expand Down
1 change: 0 additions & 1 deletion Assets/GuiTreeArrowLeft.svg.import
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
Expand Down
1 change: 0 additions & 1 deletion Assets/GuiTreeArrowRight.svg.import
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
Expand Down
1 change: 0 additions & 1 deletion Assets/GuiTreeArrowUp.svg.import
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
Expand Down
10 changes: 9 additions & 1 deletion DiscordEdit.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class_name DiscordEdit, "res://Assets/TextEdit.svg"
signal button_pressed(button)
signal text_entered(text)
signal size_changed(value)
signal text_changed(text)

export(int) var max_visible_lines: int = 5
export(String, MULTILINE) var text: String
Expand Down Expand Up @@ -63,7 +64,11 @@ func adjust_text_nodes():
rect_position.y += line_height
rect_min_size.y -= line_height


func update():
main_text.center_viewport_to_cursor()
adjust_text_nodes()
placeholder.text = placeholder_text
main_text.text = text

func _on_TextEdit_text_changed() -> void:
adjust_text_nodes()
Expand All @@ -82,3 +87,6 @@ func _on_TextEdit_gui_input(event: InputEvent) -> void:
if event.scancode == KEY_ENTER and event.shift == false and not event.echo:
emit_signal("text_entered", text)
main_text.text = ""
if event.scancode != KEY_ENTER and event.shift == false and not event.echo:
emit_signal("text_changed", text)

32 changes: 28 additions & 4 deletions Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ extends Control

export(PackedScene) var server_scene = preload("res://Scenes/Server/Server.tscn")

var config_path = "user://config.cfg"

var current_guild_id: = ""
var current_channel_id: = ""

Expand All @@ -15,8 +17,18 @@ var servers: Dictionary = {}

func _ready() -> void:
bot_node.VERBOSE = true
tab_container.current_tab = 1

var file = File.new()
if !file.file_exists(config_path):
tab_container.current_tab = 1
else:
setup_bot(config_path)
tab_container.current_tab = 2

func setup_bot(file_path):
var f = ConfigFile.new()
f.load(file_path)
bot_node.INTENTS = f.get_value("Main", "Intents", 32383)
bot_node.login(f.get_value("Main", "BotToken", ""), f.get_value("Main", "ApplicationID", ""))

func _on_DiscordBot_bot_ready(bot: DiscordBot) -> void:
print("Logged in as |%s#%s|" % [bot.user.username, bot.user.discriminator])
Expand All @@ -25,6 +37,16 @@ func _on_DiscordBot_bot_ready(bot: DiscordBot) -> void:
for guild in bot.guilds:
servers.append(bot.guilds[guild].name)
print("Ready on %s servers (guilds): %s and %s channels" % [bot.guilds.size(), servers, bot.channels.size()])
var f = ConfigFile.new()
f.load(config_path)
bot_node.set_presence({
"status": f.get_value("Main", "Status", "idle"),
"afk": f.get_value("Main", "AFK", false),
"activity": {
"type": f.get_value("Main", "Type", "listening"),
"name": f.get_value("Main", "Name", "you. Please be sane!"),
}
})

# bot_node.add_application_commands(
# {
Expand Down Expand Up @@ -67,8 +89,10 @@ func _on_DiscordBot_interaction_create(bot, interaction: DiscordInteraction) ->
pass # Replace with function body.


func _on_DiscordBot_message_create(bot, message, channel: Channel, guild: Guild):
servers[guild.id].message_recieved(message, channel)
func _on_DiscordBot_message_create(_bot, message, channel: Channel, guild: Guild):
print("message received")
yield(servers[guild.id].message_recieved(message, channel), "completed")
print("recived")


func _notification(what: int) -> void:
Expand Down
2 changes: 2 additions & 0 deletions Scenes/Commands/Commands.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ size_flags_vertical = 3
[node name="Command" parent="HSplitContainer/ScrollContainer" instance=ExtResource( 2 )]
anchor_right = 0.0
anchor_bottom = 0.0

margin_right = 390.0
margin_bottom = 464.0


[node name="RichTextLabel" type="RichTextLabel" parent="HSplitContainer"]
margin_left = 402.0
margin_right = 793.0
Expand Down
53 changes: 42 additions & 11 deletions Scenes/Config.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,69 @@ extends Control

var settings: Dictionary = {}
var f = ConfigFile.new()
var file_path: String = "user://Config.cfg"
var file_path: String = "user://config.cfg"

onready var settings_container = $SettingsContainer

var statuses = {
"invisible": "offline", # exception
"dnd": "dnd",
"online": "online",
"idle": "idle",
"offline": "offline",
"do not disturb": "dnd" # exception
}

func _ready() -> void:
f.load(file_path)
for key in f.get_section_keys("Main"):
var refined_key = key.replace(":", "")
settings[refined_key] = f.get_value("Main", key)

# print(settings)
settings["Name"] = "you. Please be sane."
for child in settings_container.get_children():
if child.get_child_count():
# print(child.get_node("Label").text.rstrip(":"))
# print(settings[child.get_node("Label").text.rstrip(":")])
if child.get_child(1) is LineEdit:

child.get_node("LineEdit").text = settings[child.get_node("Label").text.rstrip(":")]
if child.get_child(1) is CheckBox:
child.get_node("CheckBox").pressed = settings[child.get_node("Label").text.rstrip(":")]
if child.get_child(1) is OptionButton:
# print(settings[child.get_node("Label").text.rstrip(":")])
# print(find_selected_from_id(child.get_node("OptionButton"), settings[child.get_node("Label").text.rstrip(":")]))
child.get_node("OptionButton").selected = find_selected_from_id(child.get_node("OptionButton"), settings[child.get_node("Label").text.rstrip(":")])

func find_selected_from_id(button: OptionButton, text: String):
for index in button.get_item_count():
var ind_text = button.get_item_text(index)
if ind_text.to_lower() == text.to_lower():
return index
return -1

func _on_Configure_pressed() -> void:
# yield(settings_container, "ready")
for child in settings_container.get_children():
if child.get_child(1) is LineEdit and not child.get_node("LineEdit").text.empty():
settings[child.get_node("Label").text] = child.get_node("LineEdit").text
if child.get_child(1) is CheckBox:
settings[child.get_node("Label").text] = child.get_node("CheckBox").pressed
if child.get_child(1) is OptionButton:
settings[child.get_node("Label").text] = child.get_node("OptionButton").text.to_lower()

if child.get_child_count():
if child.get_child(1) is LineEdit and not child.get_node("LineEdit").text.empty():
settings[child.get_node("Label").text.rstrip(":")] = child.get_node("LineEdit").text
if child.get_child(1) is CheckBox:
settings[child.get_node("Label").text.rstrip(":")] = child.get_node("CheckBox").pressed
if child.get_child(1) is OptionButton:
settings[child.get_node("Label").text.rstrip(":")] = child.get_node("OptionButton").text.to_lower()
for key in settings:
if not settings[key]:
if settings[key]:
f.set_value("Main", key, settings[key])
f.save(file_path)

f.load(file_path)
owner.bot_node.INTENTS = settings.Intents if settings.has("Intents") else 32383
owner.bot_node.login(f.get_value("Main", $SettingsContainer/HBoxContainer/Label.text, ""), f.get_value("Main", $SettingsContainer/HBoxContainer2/Label.text, ""))
print(f.get_value("Main", $SettingsContainer/HBoxContainer/Label.text.rstrip(":"), "failing"))
print(f.get_section_keys("Main"))
owner.bot_node.set_presence({
"status": settings.Status if settings.has("Status") else "idle",
"status": statuses[settings.Status.to_lower() if settings.has("Status") else "idle"],
"afk": settings.AFK if settings.has("AFK") else false,
"activity": {
"type": settings.Type if settings.has("Type") else "listening",
Expand Down
1 change: 1 addition & 0 deletions Scenes/Config.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ margin_bottom = 46.0
size_flags_horizontal = 3
size_flags_vertical = 3
size_flags_stretch_ratio = 1.98
text = "Please be sane."
placeholder_text = "Value here...."

[node name="Configure" type="Button" parent="."]
Expand Down
52 changes: 43 additions & 9 deletions Scenes/Server/Server.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ export var message_scene = preload("res://Scenes/Server/message.tscn")
var guild: Guild
var bot: DiscordBot
var current_channel: String setget set_channel
var referenced_message: Dictionary

onready var channels_container = $HSplitContainer/ChannelContainer/Channels
onready var members_container = $HSplitContainer/HSplitContainer/MembersContainer/Members
onready var messages_container = $HSplitContainer/HSplitContainer/MessagesContainer/MessageContainer/Messages
onready var typing_label = $HSplitContainer/HSplitContainer/MessagesContainer/Typing
onready var timer = $Timer

onready var discord_edit = $HSplitContainer/HSplitContainer/MessagesContainer/DiscordEdit

func _ready() -> void:
name = guild.name
Expand Down Expand Up @@ -50,13 +51,33 @@ func set_channel(value: String) -> void:
yield(get_tree(), "idle_frame")
message_recieved(message, channel)


discord_edit.placeholder_text = "Message #%s" % channel.name
discord_edit.update()

# var last_message: Message = yield(channel.get_message(bot, channel.last_message_id, channel.id), "completed")
# message_recieved(last_message, channel)


func reply_pressed(message: Message):
$HSplitContainer/HSplitContainer/MessagesContainer/ReplyMessage.text = "Replying to %s" % message.author.username
$HSplitContainer/HSplitContainer/MessagesContainer/ReplyMessage.show()
print(message.guild_id, "test", message.channel_id, message.id)
if message.guild_id:
referenced_message = {"message_id": message.id, "channel_id": message.channel_id, "guild_id": message.guild_id}
else:
referenced_message = {"message_id": message.id, "channel_id": message.channel_id}


func _on_DiscordEdit_text_entered(text: String):
if text != "":
Channel.create_message(bot, {"content": text}, current_channel)
if referenced_message:
Channel.create_message(bot, {"content": text, "message_reference": referenced_message, "type": 19}, current_channel)
else:
Channel.create_message(bot, {"content": text}, current_channel)
if $HSplitContainer/HSplitContainer/MessagesContainer/ReplyMessage.visible:
$HSplitContainer/HSplitContainer/MessagesContainer/ReplyMessage.hide()
referenced_message = {}

func message_recieved(message: Message, channel: Channel):
typing_label.hide()
Expand All @@ -68,23 +89,32 @@ func message_recieved(message: Message, channel: Channel):
var new_message = message_scene.instance()
# var avatar = yield(message.author.get_display_avatar({"size": 128}), "completed")
new_message.bot = bot
var avatar = yield(message.author.get_display_avatar({size = 128}), "completed")
new_message.author = message.author
var avatar = yield(message.author.get_display_avatar({"size": 128}), "completed") # this is what Godot Docs say to use.
new_message.avatar = Helpers.to_image_texture(Helpers.to_png_image(avatar))
new_message.content = message.content
new_message.name = message.id
# var current_time = OS.get_datetime_from_unix_time(int(message.timestamp))
# var time_zone = OS.get_time_zone_info()
# print(time_zone)
new_message.author_name = message.author.username
var timestamp
if message.edited_timestamp:
timestamp = Helpers.get_local_time(message.edited_timestamp)
else:
timestamp = Helpers.get_local_time(message.timestamp)
new_message.time = "%s %s" % [Helpers.get_date(timestamp), Helpers.get_time(timestamp)]

new_message.time = "Today at %s" % Helpers.get_time()
new_message.author = message.author
new_message.content = message.content
new_message.name = message.id

messages_container.add_child(new_message)
new_message.connect("reply_pressed", self, "reply_pressed", [message])
new_message.message = message
if message.edited_timestamp:
new_message.edited_node.show()
# new_message.get_parent().move_child(new_message, 0)


func set_typing(bot, dict: Dictionary):
if current_channel == dict.channel_id:
if current_channel == dict.channel_id and dict.member.user.id != bot.user.id:
timer.start()
if dict.member.has("nick") and dict.member.nick:
typing_label.text = "%s is typing..." % dict.member.nick
Expand All @@ -95,3 +125,7 @@ func set_typing(bot, dict: Dictionary):

func _on_Timer_timeout() -> void:
typing_label.hide()


func _on_DiscordEdit_text_changed(text):
Channel.send_typing(bot, current_channel)
Loading