1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
#!/usr/bin/env python3
"""Test script for Discord embed functionality."""
import os
import sys
from dotenv import load_dotenv
# Add the src directory to the Python path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
from umabot.discord_client import DiscordWebhookClient
def test_discord_embed():
"""Test the Discord embed functionality."""
# Load environment variables
load_dotenv()
# Get Discord configuration
webhook_url = os.getenv("DISCORD_WEBHOOK_URL")
channel_id = os.getenv("DISCORD_LOG_CHANNEL_ID")
if not webhook_url:
print("โ Error: DISCORD_WEBHOOK_URL not found in environment variables")
print("Please set DISCORD_WEBHOOK_URL in your .env file")
return False
print(f"๐ Using webhook URL: {webhook_url[:50]}...")
if channel_id:
print(f"๐บ Using channel ID: {channel_id}")
else:
print("๐บ Using webhook's default channel")
# Initialize Discord client
discord_client = DiscordWebhookClient(webhook_url, channel_id)
print("\n๐งช Testing Discord embed functionality...")
# Test 1: Reflair action
print("\n1๏ธโฃ Testing reflair action embed...")
success1 = discord_client.log_moderation_action(
action="Reflair to Art",
submission_id="test123",
author="testuser",
title="Beautiful artwork of my favorite character!",
reason="The post contains primarily visual artwork content with minimal textual roleplay elements, focusing more on showcasing the artwork rather than engaging in character-driven narrative or dialogue.",
post_url="https://reddit.com/r/test/comments/test123/"
)
if success1:
print("โ
Reflair embed sent successfully!")
else:
print("โ Failed to send reflair embed")
# Test 2: Removal action
print("\n2๏ธโฃ Testing removal action embed...")
success2 = discord_client.log_moderation_action(
action="Removed",
submission_id="test456",
author="anotheruser",
title="Short post with minimal content",
reason="Content needs more development, short length, no plot development, lacks creativity, minimal detail, no character development, content that doesn't meet community standards",
post_url="https://reddit.com/r/test/comments/test456/"
)
if success2:
print("โ
Removal embed sent successfully!")
else:
print("โ Failed to send removal embed")
# Test 3: Long reason truncation (simulating real behavior)
print("\n3๏ธโฃ Testing long reason truncation...")
success3 = discord_client.log_moderation_action(
action="Removed",
submission_id="test789",
author="longreasonuser",
title="Another test post",
reason="This is a very long reason that should be truncated in the actual implementation because the intelligent moderator truncates reasons to 100 characters plus ellipsis when they are too long, just like this one which is definitely longer than 100 characters and should demonstrate the truncation behavior for content that needs more development",
post_url="https://reddit.com/r/test/comments/test789/"
)
if success3:
print("โ
Long reason embed sent successfully!")
else:
print("โ Failed to send long reason embed")
# Test 4: Custom embed
print("\n4๏ธโฃ Testing custom embed...")
custom_embed = {
"title": "๐งช Test Embed",
"description": "This is a test embed to verify the Discord webhook functionality.",
"color": 0x0099ff, # Blue color
"fields": [
{
"name": "๐ Test Status",
"value": "โ
All systems operational",
"inline": True
},
{
"name": "๐ง Bot Version",
"value": "UmaBot v1.0",
"inline": True
},
{
"name": "๐ Test Details",
"value": "This embed was generated by the test script to verify Discord webhook integration.",
"inline": False
}
],
"footer": {
"text": "UmaBot Test Script"
}
}
success4 = discord_client.send_embed(custom_embed)
if success4:
print("โ
Custom embed sent successfully!")
else:
print("โ Failed to send custom embed")
# Summary
print("\n๐ Test Summary:")
print(f" Reflair embed: {'โ
Success' if success1 else 'โ Failed'}")
print(f" Removal embed: {'โ
Success' if success2 else 'โ Failed'}")
print(f" Long reason embed: {'โ
Success' if success3 else 'โ Failed'}")
print(f" Custom embed: {'โ
Success' if success4 else 'โ Failed'}")
total_success = sum([success1, success2, success3, success4])
print(f"\n๐ฏ Total: {total_success}/4 tests passed")
if total_success == 4:
print("๐ All tests passed! Discord embed functionality is working correctly.")
return True
else:
print("โ ๏ธ Some tests failed. Check your Discord webhook configuration.")
return False
def main():
"""Main function."""
print("๐ค UmaBot Discord Embed Test Script")
print("=" * 50)
try:
success = test_discord_embed()
sys.exit(0 if success else 1)
except KeyboardInterrupt:
print("\n\nโน๏ธ Test interrupted by user")
sys.exit(1)
except Exception as e:
print(f"\nโ Unexpected error: {e}")
sys.exit(1)
if __name__ == "__main__":
main()
|